0% found this document useful (0 votes)
4 views

Lab1[1]

The document outlines the lab policies and rules for a Software Engineering course, emphasizing mandatory attendance, penalties for disruptions, and the importance of understanding lab tasks. It provides an introduction to basic Linux commands and file system organization, detailing commands like cd, pwd, mkdir, and rm, along with their usage and examples. Additionally, it includes a series of tasks for students to complete, focusing on practical application of the commands learned.

Uploaded by

ahmedmukarram6
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lab1[1]

The document outlines the lab policies and rules for a Software Engineering course, emphasizing mandatory attendance, penalties for disruptions, and the importance of understanding lab tasks. It provides an introduction to basic Linux commands and file system organization, detailing commands like cd, pwd, mkdir, and rm, along with their usage and examples. Additionally, it includes a series of tasks for students to complete, focusing on practical application of the commands learned.

Uploaded by

ahmedmukarram6
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

CL 2006 OPERATING SYSTEM

BS Software Engineering
Fall-2024

Course Instructors: Syed Daniyal Hussain Shah, Hifza Umar


Course Coordinator: Syed Daniyal Hussain Shah

Page 1
Lab Policy and Rules:

1. 100% attendance is mandatory. In case of an emergency, you can avail yourself of up to 3 absences.
So, don't waste your absences , save them for emergencies. If you are debarred from the course due to
low attendance, do not come to me to correct it.

2. Disturbing the class environment during lab sessions. such as by talking, using mobile phones, eating,
etc. will result in penalties (e.g., deduction of marks).

3. Lab tasks will not be accepted if you are absent. If you miss a lab, you cannot submit that lab task.

4. Lab demos for each lab task will be conducted at the end of each session. If you miss the demo for
any reason, no retake will be allowed, and that lab will be marked as 0.

5. All quizzes will be unannounced. Be prepared for surprise quizzes. Quizzes will cover content from
previous labs as well as theory lectures from the corresponding theory course.

6. You can take help from the internet for lab tasks, but simply copying and pasting without
understanding will be marked as 0. You should be able to explain the syntax or material used in your
tasks.

7. Do not ask for personal favors. If you have concerns, such as short attendance, please speak with the
relevant authority (e.g., academics).

8. Students on warning: Now is the time to study and earn a good grade. Do not ask for extra marks at
the end if you are unable to clear your warning.

Lab 1: Introduction to shell and some basic linux commands

1. Shell:
The shell is a command-line interpreter that provides a user interface for interacting
with the operating system. It allows users to execute commands, run scripts, and

Page 2
manage files and processes. The shell interprets the commands you type and translates
them into actions by the operating system.

2. Terminal:
The terminal is a software application that provides a text-based interface to interact
with the shell. It's where you type your commands and see the output. Essentially, the
terminal acts as a container for the shell, allowing you to interact with it.

3. Organization of linux file system:


 Root directory:
The root directory in Linux, represented by a single forward slash /, is the top-
level directory in the file system hierarchy. All other files and directories are
nested within this directory, forming a tree-like structure.

 Directory:
A folder which holds other files and folders.

 Subdirectory:
A directory residing within another directory.

 Current working directory:


The directly currently being used.

 Home directory:
The directory selected by the linux as the working directory when a user logs in.
Its name usually matches with your login name.

Example:
/home/ahmed (path of ahmed home directory).

 Path/Pathname:
A path or pathname is the specific location of a file or directory in the file
system. It tells the system where to find or place a file or directory. There are
two types of paths: absolute paths and relative paths.

Example "C:\Users\HP\Desktop\BootCamp"

a. Absolute pathname:
An absolute path specifies a file or directory's location in the file system
starting from the root directory (/). It provides the full path from the
root to the file or directory, regardless of the current working directory.

Example:
/home/user/documents/report.txt

Page 3
b. Relative pathname:
A relative path specifies a file or directory's location relative to the
current working directory. It does not start from the root directory but
rather from wherever you are currently located in the file system.

Example:
If your current working directory is /home/user:

documents/report.txt refers to the report.txt file inside the


documents directory within the current directory (/home/user).

../config/settings.conf would refer to the settings.conf file


located in the config directory, which is one level up from the
current directory.

c. Special Symbols in Paths:


( / ): Root directory or directory separator.

( .. ) : Refers to the parent directory (one level up).

4. cd command:
The cd (change directory) command in Linux is used to navigate the file system by
changing the current working directory to a different directory. This command is one of
the most basic and frequently used in the terminal.

To navigate to a directory named documents:

To move to a directory using an absolute path:

Change to a directory using a relative path:

To move to the parent directory of your current location:

Simply typing cd without any arguments will take you to your home directory:

Page 4
You can also use the tilde (~) symbol:

To navigate directly to the root directory:

To switch back to the previous directory you were in:

5. pwd command:
The pwd (print working directory) command in Linux is used to display the absolute path
of the current working directory. It shows you where you are in the file system at any
given moment. pwd always shows the absolute path, starting from the root (/).

Example:

Output:

6. mkdir command:
The mkdir (make directory) command in Linux is used to create one or more new
directories. It allows you to specify the name and location of the directories you want to
create.

Examples:
To create a directory named new_folder in the current directory.

To create several directories at once:

Page 5
To create a directory within another directory (if the parent directory exists):

If you want to create a directory and any necessary parent directories that don’t already
exist, use the -p option:

7. rmdir:
The rmdir (remove directory) command is specifically used to delete empty directories.
It will only remove a directory if it is empty; if the directory contains any files or
subdirectories, rmdir will not remove it and will return an error.

Examples:
Remove an empty directory:

Remove multiple empty directories:

8. rm:
The rm (remove) command is used to delete files and directories. Unlike rmdir, rm can
delete both files and directories, and it does not require directories to be empty. The rm
command is more powerful and versatile, but it also requires careful use because it can
permanently delete files and directories.

Examples:
Remove a directory and its contents:

Remove an empty directory:

Page 6
9. mv:
The mv command in Linux is used for moving and renaming files and directories. It's a
versatile command that can relocate files from one directory to another or change their
names within the same directory.

Examples:
Rename a File:

Rename a Directory:

Move a File to a Different Directory:

Move Multiple Files to a Directory:

Move a Directory to Another Location:

Prevent Overwriting Existing Files:

If destination_file.txt exists, it will not be overwritten.

You can use wildcards (*) to move multiple files that match a certain pattern.

Page 7
10. cp:
The cp command in Linux is used to copy files and directories from one location to
another. It's a fundamental command for file management, allowing you to duplicate
files or entire directory structures.

Examples:
Copy a Single File:

Copy a File to Another Directory:

Copy Multiple Files:

Copy a Directory and Its Contents:

The -r (recursive) option is necessary to copy directories. This command copies


the entire source directory and its contents to the destination.

Do not overwrite an existing file.

11. ls:
The ls command in Linux is used to list the contents of a directory. It displays files,
directories, and other types of items within the specified directory or the current
directory if no directory is specified.

Page 8
Examples:
Running ls without any options simply lists the names of files and directories in
the current directory.

Displays detailed information about each file or directory, including permissions,


number of links, owner, group, size, and modification date.

Lists all files, including hidden files (those starting with a dot ( .).

Lists all files and directories recursively, showing the contents of all
subdirectories.

The -t option sorts the files and directories by their last modification time. The
most recently modified items are listed first.

The -s option sorts files and directories by their size, displaying the largest files
first.

The -r option reverses the order of the listing.

Single Commands
 To clear the screen

Page 9
Syntax: $ clear
 To view commands history
Syntax: $ history
 To display first 10 lines of a file
Syntax: $ head file.txt
 To display first 6 lines of a file
Syntax: $ head —n 6 file.txt
 To display first 5 lines from 2 files
Syntax: $ head —n 5 title .txt file2.txt
 To display last 10 lines of a file
Syntax: $ tail file.txt
 To display last 6 lines of a file
Syntax: $ tail —n 6 file.txt
 The wc command without passing any parameter will display a basic
result Of "file_txt' file. Result Of wc command will be (number of lines),
(number or words) and (number of chars/bytes) of the file.
Syntax: $ wc file.txt
 To display the number or characters in a file
Syntax: $ wc —c file.txt
 To display the number of lines
Syntax: $ wc—I file.txt
 To display the number of words
Syntax: $ wc —w file.txt
 TO display number Of lines with numbers
Syntax: $ nl file.txt
 To sort the content of file
Syntax: $ sort file.txt
 To sort the content Of file in reverse orderz
Syntax: $ sort -r file-txt
 To display the calendar.
Syntax: $ cal
 To display system date.
Syntax: $ date
 To display the login user details

Page 10
 Syntax: $ whoami
 To display the contents of a file, line by line and page by page. we can use
less command.
Syntax: $ less file.txt
 Note: to move up or down line by line use Arrow keys. And to move up
page by page use 'b' key and for move down use Space key. To quit form
the less command use ‘q' key.
 To copy the file to another file
$ cp file1 -txt file2.txt
 To copy a file within the other directory
$ cp file2.txt Documents/directory1
 To move a file to another directory
$ rmv file1.txt directory2
$ mv —Documents/file1.txt directory3
 To rename a file:
 $ mv file1.txt file2.txt
 $ mv —Documents/file1.txt —/Doeuments/file2.txt
 To delete a file
$ rm file1.txt
 $ rm Dir1/file2.txt

Task:

1. Create a New Directory

2. Create a Nested Directory Structure (parent/child/grandchild/)

3. Create Multiple Directories in One Command

4. Remove an Empty Directory

Page 11
5. Try to Remove a Directory Named `non_empty_dir` ( parent)
Note: This command will remove the directory and all its contents. Use with caution.

6. Remove a File Named `file1.txt`

7. Remove a Directory Named `dir1` and All of Its Contents

8. Remove an Empty Directory Named `dir2`

9. List All Files in the Current Directory, Including Hidden Files

10. List Files Sorted by Modification Time (Most Recently Modified First)

11. List Files Sorted by Size (Largest First)

12. Copy a File Named `file1.txt` to a New File Named `file2.txt`

13. Copy a Directory Named `source_dir` and Its Contents to a New Directory Named
`destination_dir`

14. Copy a File Named `file1.txt` to `file2.txt`, but Only if `file2.txt` Does Not Already
Exist

15. Copy Only the Contents of `source_dir` to `destination_dir`, Without Copying


`source_dir` Itself

16. Move a Directory Named `dir1` to a New Location or Rename It to `dir2`.


17. Change to an Absolute Path Directory (e.g., `/home/user/Documents`)
18. Change to the Root Directory of the File System

19. Change to Your Home Directory Using Its Absolute Path

20. If There’s a Directory Named `My Projects` Under `/home/user`, Navigate to It


21. From Your Current Directory, Navigate to a Subdirectory Named `docs`

22. Move Up One Directory Level From Your Current Location

23. Move Up Two Directory Levels From Your Current Location

Page 12
24. If You Are in `/home/user/Projects/2024`, Navigate Up to `Projects` and Then to a
Subdirectory `old_projects`

25. From Any Directory, Change to Your Home Directory Without Using the Name of the
Home Directory

26. Create a File with Initial Content

27. List All Files Including Hidden Files, with Human-Readable Sizes

28. Find and List All Files with a Specific Extension (e.g., `.txt`)

29. Find and Remove All `.log` Files in the Current Directory and Subdirectories

30. Display Disk Usage of the Current Directory and Subdirectories

31. Check Available Disk Space

32. Show the Full Path of the Current Directory

Task Submission Guidelines:


1. Make a word document and paste all solutions there and save it as pdf or odt.
2. Include your name and roll no. at the front page.
3. Files other than pdf or odt will not be accepted and will be marked as 0.

Page 13

You might also like