Basic Commands For Os
Basic Commands For Os
Basic Commands For Os
WEEK-3
PERFORMANCE CRITERIA
FILE AND DIRECTORY COMMANDS
I]
1. mkdir command
This command is used to create or make new directory.
SN Example Meaning
1 $ mkdir cse creates a new directory called “cse”
2 $ mkdir cse ce me creates 3 new directory namely “cse”, “ce”, “me”
3 $ mkdir – v cse creates a new directory called “cse” in verbose mode(v) it prints
confirmation message directory is created
2. rmdir command
This command is used to remove empty directories present in your system.
SN Example Meaning
1 $ mkdir cse removes the directory called “cse”
3 $ mkdir – v cse removes the directory called “cse” in verbose mode
3. touch command
This command is used to create file.
Syntax $ touch test.txt
5. cat command
The cat command is short for concatenate. It can be used to output the contents of
several files, one file, or even part of a file. If the file doesn’t exist, the Linux cat command will
create it.
Syntax $ > cat test3.txt
6. rm command
This command is used to delete or remove files.
Syntax $ > rm [options] filename / directoryname
S Example Meaning
N
1 $ rm f1.c removes the file “f1.c”
2 $ rm -i f1.c prompt before deleting the file “f1.c”
3 $ rm - d cse removes the directory “cse”
4 $ rm *.c removes all the c files
7. mv command
This command is used to move the files and directories.
Syntax $ mv [options] source destination
SN Example Meaning
1 $ mv f1.c gptkgf Moves f1.c to the directory gptkgf
SN Example with Meaning
options
1 $ mv - i f1.c gptkgf Same as above but there is interactive prompt before moving
mv:move ‘gptkgf/f1.c’ ? y
8. cp command
This command is used to copy the contents of files and directories to other files and
directories.
Syntax $ cp [options] source destination
SN Example Meaning
1 $ cp f1.c f2.c Copies the contents of f1.c to f2.c
SN Example with Meaning
options
1 $ cp - a f1.c gptkgf Copies the contents of f1.c to the directory gptkgf
2 $ cp - R f1.c gptkgf Copies the contents of f1.c to the directory gptkgf
3 $ cp - i f1.c gptkgf Same as above but there is interactive prompt before copying
cp:overwrite ‘gptkgf/f1.c’ ? y
9. Pipes
Named pipe: named pipe is also called as FIFO special file. An unnamed pipe is only
used for communication between a child and its parent process.
$ mkfifo mypipe
$ ls -l mypipe
prw-r-----. 1 shs staff 0 Jan 31 13:59 mypipe
$ cat mypipe
Unnamed pipe: named pipe can be used for communication between two unnamed
process.
The input parameter is an array of two file descriptors fd[0] and fd[1]. The system
call returns a –1 in case of a failure. If the call is successful, it will return two
integer values which are file descriptors fd[0] & fd[1]. In half-duplex pipes, fd[0]
and fd[1] are used for reading and writing, respectively.
II]
1. ls command
This command is used to list the files and directories present in the system.
Syntax $ ls [options] filename/dirname
SN Example Output
1 $ ls Desktop Downloads....
Documents......
SN Example with options Meaning
1 $ ls -r Lists all files & directories in reverse order (z-a)
2 $ ls -ls Lists all files in long format along with file size
3 $ ls -t Lists all files sorted by time and date
4 $ ls -a Lists all files & also hidden files starting with . (dot)
5 $ ls -l Lists all files & directories in a long list format
2. comm command
This command is used to compare two files line by line.
Syntax $ comm [options] filen1 filen2
3. cmp command
This command is used to compare two files byte by byte. It displays the byte and line
number where first difference is found. If no difference is found no output will be displayed.
Syntax $ cmp [options] file1 file2
SN Example Meaning
1 $ cmp f1.txt f2.txt Compares the files f1.txt and f2.txt
Output:- differ: byte 15, line 3
5. chmod command
This command is used for changing the file permissions.
chmod stands for “change mode”
We can change permission for all 3 categories of user (user, group, others)
The command can be specified in two ways
a) Relative permissions
When using this method, chmod changes the permissions specified in the
command and leaves the other permission unchanged.
SN Example Output
1 $ chmod u + x f.txt Adds execute permission on file f.txt for the user
2 $ chmod o + x f.txt Adds execute permission on file f.txt for the others
Dept. of CSE, GPT-KGF 2021-2022 5
20CS42P- OS & ADMINISTRATION Prepared by: NANDINI V, L/CSE GPT-KGF
3 $ chmod o - x f.txt Removes execute permission on file f.txt for the others
4 $ chmod a + x f.txt Adds execute permission on file f.txt for the user,
group and others (all)
5 $ chmod o + x f.txt f1.txt Adds execute permission on file f.txt and f1.txt for the
others
b) Absolute permissions
In this method chmod uses 3-digit code.
Digits assigned for read = 4
write = 2
execute = 1
SN Example Output
1 $ chmod 777 f.txt Adds read, write and execute permission on file f.txt for all
2 $ chmod 766 f.txt User = r w x
Group = r w
Others = r w
gzip -d & unzip: this command with option d is used to decompress the given file.
Syntax Description Example
gzip -d {.gz file} Decompressed a file that is created gzip -d mydata.doc.gz
using gzip command. File is
restored to their original form
using this command.
unzip {.zip file} Extract the compressed files unzip file.zip
II]
01 joe
02 marie
03 albert
04 dave
SN Example Output
1 $ sort sort.txt sorts the content of the file sort.txt
01 joe
02 marie
03 albert
04 dave
03 albert
02 marie
01 joe
3 $ paste - k 2 sorts the content of the file sort.txt based on the
sort.txt key (k) 2 represents the second coloumn
03 albert
04 dave
01 joe
02 marie
u.txt
this is a line
this is a line
this is a line
this is also a line
SN Example Output
1 $ uniq u.txt displays only single copy of each line present in u.txt
this is a line
this is also a line
this is also also a line
2 $ uniq - c u.txt displays only single copy of each line present in u.txt along
with their count
3 this is a line
2 this is also a line
1 this is also also a line
3 $ uniq - d u.txt displays only the lines at are duplicate in u.txt
this is a line
this is also a line
This command removes or cuts the section of each line of a specified file.
SN Example Output
1 $ cut - f 4 cut.txt four
peach
2 $ cut - f 2-3 cut.txt two three
Dept. of CSE, GPT-KGF 2021-2022 8
20CS42P- OS & ADMINISTRATION Prepared by: NANDINI V, L/CSE GPT-KGF
grapes mango
3 $ cut - f 1, 4, 6 cut.txt one four six
apple peach kiwi
In the above examples f stands for field
SN Example Output
1 $ paste a.txt b.txt displays the content of a.txt and b.txt in parallel
here tab is used as a delimiter
2 $ paste - d ‘:’ a.txt b.txt displays the content of a.txt and b.txt in parallel
here : is used as a delimiter
3 $ paste - s a.txt b.txt displays the content of a.txt and b.txt one after
the another (in serial)
v. head command
SN Example Output
1 $ head f1.txt prints the first 10 lines of the file f1.txt
2 $ head - 4 f1.txt prints only the first 4 lines of the file f1.txt
3 $ head - c 4 f1.txt prints only the first 4 characters of the file f1.txt
vi. tail command
SN Example Output
1 $ tail f1.txt prints the last 10 lines of the file f1.txt
2 $ tail - 4 f1.txt prints only the last 4 lines of the file f1.txt
3 $ tail - c 4 f1.txt prints only the last 4 characters of the file f1.txt
vii. tr command
t.txt
hello
SN Example Output
1 $ tr “[:lower:]” “[:upper:]” < t.txt HELLO
viii. pr command
SN Example Output
1 $ pr - h “” u.txt prints the file with file name (u.txt) as the page header
2 $ pr - m u.txt prints the file in parallel (merge)
Regular Expression: They provide the way for matching patterns in a given input.
reg.txt
SN Example Meaning
1 $ grep “linuxlab” reg.txt displays/matches any line that contains the word
“linuxlab”
this is my linuxlab
2 $ grep “this.” reg.txt displays any line that contains the word “this” and
“this” should not be present at end of the line.
hello this is gpt (kgf)
this is my linuxlab
3 $ grep “this*” reg.txt displays any line that contains the word “this”
hello this is gpt (kgf)
this is my linuxlab
bye take care this
4 $ grep “[^t]his” reg.txt displays any line that contains the spelling “his”
and beginning character of “his” should not be “t”
This is abc from 4th sem cse
WEEK-3 ACTIVITY
Ext2 stands for second Ext3 stands for third Ext4 stands for fourth
extended file system. extended file system. extended file system.
This was developed to Starting from Linux Kernel Starting from Linux Kernel
overcome the limitation of 2.4.15 ext3 was available. 2.6.19 ext4 was available.
the original ext file system.
Ext2 does not have The main benefit of ext3 is Supports huge individual file
journaling feature. that it allows journaling. size and overall file system
size.
Maximum individual file size Maximum individual file size Maximum individual file
can be from 16 GB to 2 TB can be from 16 GB to 2 TB size can be from 16 GB to 16
TB
Overall ext2 file system size Overall ext3 file system size Overall maximum ext4 file
can be from 2 TB to 32 TB can be from 2 TB to 32 TB system size is 1 EB
(exabyte). 1 EB = 1024 PB
(petabyte). 1 PB = 1024 TB
(terabyte).