0% found this document useful (0 votes)
111 views7 pages

1.2 Worksheet OS Lab-1

This document describes an experiment conducted by a student to study basic Linux commands like ls, head, tail, grep, man, pwd, chmod, and cat. It provides details on how each command works, examples of usage, and flags that can be used. The student learned how to use these commands to copy, move, remove, and view files and directories, and get information about permissions and contents.

Uploaded by

Sarthak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views7 pages

1.2 Worksheet OS Lab-1

This document describes an experiment conducted by a student to study basic Linux commands like ls, head, tail, grep, man, pwd, chmod, and cat. It provides details on how each command works, examples of usage, and flags that can be used. The student learned how to use these commands to copy, move, remove, and view files and directories, and get information about permissions and contents.

Uploaded by

Sarthak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Experiment :1.

Student Name: Rajnish Mani Tiwari UID: 20BCS3950


Branch: CSE- BIG DATA Section/Group: 20BD2A
Semester: 3rd Date of Performance: 25\8\2021
Subject Name: Operating system Subject Code: 20CSP-232

Aim/Overview of the practical:


To Study basic Linux commands like ls, head, tail, grep, Man, Pwd, chmod, cat.

Pwd (present working directory):


It prints the path of the working directory, starting from the root.pwd is shell built-in
command(pwd) or an actual binary(/bin/pwd). PWD is an environment variable which stores
the path of the current directory.
This command has two flags.

pwd -L: Prints the symbolic path.


pwd -P: Prints the actual path.

ls command:
The ls command is used to view the contents of a directory. By default, this command will
display the contents of your current working directory.

if you want to see the content of other directories, type ls and then the directory’s path. For
example, enter ls /home/username/Documents to view the content of Documents.
There are variations you can use with the ls command:

ls -R will list all the files in the sub-directories as well

ls -a will show the hidden files

ls -al will list the files and directories with detailed information like the permissions, size,
owner, etc.
ls-l:
The -l option signifies the long list format. This shows a lot more information presented to the
user than the standard command. You will see the file permissions, the number of links, owner
name, owner group, file size, time of last modification, and the file or directory name. This option
is used in conjunction with many other options on a regular basis.

Ls -p:
The ls command is one of the most commonly used commands in daily Linux/UNIX
operations. The command is used in listing contents inside a directory and is one of the few
commands beginners learn from the onset.

Man:
• It provides online documentation for all the possible options with a command and its
usages.

• Syntax: man command

• Example: man cat

Clear:
TO clear the previous screen

MKDIR:
1)The “mkdir” (Make directory) command create a new directory.

2)If directory already exists, it will return an error message “cannot create folder, folder already
exists”.

Syntax: mkdir directory_name

Example: mkdir student

Use mkdir command to make a new directory — if you type mkdir Music it will create a directory
called Music.

There are extra mkdir commands as well:

• To generate a new directory inside another directory, use this Linux basic command mkdir
Music/Newfile
• Use the chmod command
• Chmod is another Linux command, used to change the read, write, and execute permissions
of files and directories. As this command is rather complicated, you can read the full
tutorial in order to execute it properly.

CAT:
• It is used to create a file with content.

• And can concatenate two or more file contents.

• Syntax: cat > filename

• Example: cat > file1


Cat(concatenate) command is very frequently used in Linux. It reads data from the file and
gives their content as output. It helps us to create, view, concatenate files. So let us see some
frequently used cat commands.

1. To view a single file


a. Command: cat filename
2. To view multiple files
a. Command: cat file1 file2
3. To view contents of a file preceding with line numbers.
a. Command: cat -n filename
4. Create a file
a. Command: cat >newfile
5. Copy the contents of one file to another file.
a. Command: cat [filename-whose-contents-is-to-be-copied] > [destination-filename]
6. Cat command can suppress repeated empty lines in output
a. Command: cat -s geeks.txt

cd command:
To navigate through the Linux files and directories, use the cd command. It requires either the
full path or the name of the directory, depending on the current working directory that you’re in.

Let’s say you’re in /home/username/Documents and you want to go to Photos, a subdirectory of


Documents. To do so, simply type the following command: cd Photos.

Another scenario is if you want to switch to a completely new directory, for


example,/home/username/Movies. In this case, you have to type cd followed by the directory’s
absolute path: cd /home/username/Movies.

There are some shortcuts to help you navigate quickly:

• cd .. (with two dots) to move one directory up


• cd to go straight to the home folder
• cd- (with a hyphen) to move to your previous directory

On a side note, Linux’s shell is case sensitive. So, you have to type the name’s directory exactly
as it is.

cp command:
Use the cp command to copy files from the current directory to a different directory. For
instance, the command cp scenery.jpg /home/username/Pictures would create a copy of
scenery.jpg (from your current directory) into the Pictures directory.

rmdir command:
If you need to delete a directory, use the rmdir command. However, rmdir only allows you to
delete empty directories.

rm command:
The rm command is used to delete directories and the contents within them. If you only want to
delete the directory — as an alternative to rmdir — use rm -r.

Note: Be very careful with this command and double-check which directory you are in. This
will delete everything and there is no undo.

grep command:
Another basic Linux command that is undoubtedly helpful for everyday use is grep. It lets you
search through all the text in a given file.

To illustrate, grep blue notepad.txt will search for the word blue in the notepad file. Lines that
contain the searched word will be displayed fully.
head command:
The head command is used to view the first lines of any text file. By default, it will show the
first ten lines, but you can change this number to your liking. For example, if you only want to
show the first five lines, type head -n 5 filename.ext.

tail command:
This one has a similar function to the head command, but instead of showing the first lines, the
tail command will display the last ten lines of a text file. For example, tail -n filename.ext.

chmod command:
chmod is another Linux command, used to change the read, write, and execute permissions of
files and directories. As this command is rather complicated, you can read the full tutorial in
order to execute it properly.

Learning outcomes (What I have learnt):


1. I learned How to use different Linux commands.s
2. I learned how to Copy, move and remove files and directories individually.
3. I learned to Copy multiple files and directories recursively.
4. And also about cd command.
5. I also learned how to use Grep, chmod and head and tail commands.
Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
2.
3.

You might also like