OPERATING SYSTEM LAB. MANUAL
Lab.1 : Linux Commands:
$ ls (list short)
this command is used for finding out what is in the current directory. It
list the contents of the current working directory.
$ ls –a : used for listing all files including hidden
$ ls –l : used for listing all files in details excluding hidden files
$ ls list* : used for listing the files that names start with “list” in the
current workng director
$ ls *list : used for listing the files
that names ends with “list” in the current working directory
$ ls ~/betul : used for listing the contents of your betul directorywhich
isunder your home directory
$ mkdir (make directory)
this command is used for creating a new directory into the present working
directory.
$ mkdir betul : used for creating a directory called betul into the current
working directory.
$ cd (change directory)
this command is used for changing the cureent working directory to a
different directory.
$ cd betul : changes the current working directory to the directory called
betul
$ cd : used for returning the home directory
$ cd .. :used for taking one directory up in the hierarchy
Note: In unix and linux there are two special directories called ‘.’(dot) and
‘..’(two dot or double dot). ‘.’ means the current directory and ‘..’ means
the parent of the current directory
$ pwd (print working directory)
this command is used for finding out the absolute pathname of your present
working directory.
$ cp (copy)
this command used for copying files.
$ cp filename copy-filename
: is used for copying a file with
another name at the same directory
$ cp filename directoryname : is used for copying a file from the
current directory to another subdirectory. In this case the file is copied with
the same name
$ cp filename directoryname/new-filename : is used for copying a
file from the current directory to another subdirectory. In this case the file
is copied with diffrent name.
$ cp ../filename : is used for copying the file from the directory
above (represented by “..”) to the current directory
$ mv (move)
this command is used for renaming or moving files.
$ mv old-filename new-filename : renames original file with
new-filename
$ mv filename directory-name/filename : moves file to another directory
with keeping the same filename
$ mv filename directory-name/new-filename : moves file to another
directory with giving another filename
$ rm (remove)
this command is used for deleting files.
$ rm filename : removes file from the current directory
$ rm director-name : removes the file from another directory
$ rm ../filename : removes file from directory above
$ rmdir (remove directory)
this command is used for removing directory. Note that unix will not allow removing non-empty directories.
$ rm –r directory-name : is used for removing a directory with files. ( -r
means recursive)
$ clear (clear screen)
this command clears all text and leave $ prompt at the top of the window.
$ find
this command is used for finding files. It is used with –name flag. The directory must be specified.
$ find . –name myfile :
searches the file called myfile in the current directory
$ find directory/ -name myfile : seaches the file called my file in
the given directory
$ less
$ head
this command is
used for displaying the contents of a file on the screen. By deafult it displays first ten lines of a
file.
$ head –6 myfile
: displays the first 6 lines of the file
$ tail
this command is
used for displaying the contents of a file on the screen. By deafult it displays last ten lines of a
file.
$ tail –6 myfile : displays the last 6 lines of the
file
$ cat
(concatenate)
this command is
used for displaying the contents of a file on the screen. If the file is longer
than the size of the window, it scrolls past making it unreadable
If the cat command is written without specifying a file to read, it reads the standard input and on receiving the “end of file” (^D), copies it to the standard output.
Ex1. Ex.2
$ cat $ cat
bir bir
iki bir
uc iki
^D iki
bir uc
iki uc
uc ^D
$ $
The ‘>’ symbol is used for redirecting the output of a command.
$ cat > list1
apple
Creates a list1 file that contains a list of fruit
banana
pear
^D
The ‘>>’ symbol is used for appending standard output to a file.
Adds more items to the file list1
$ cat >>list1
grape
pineapple
^D
$ cat list1 list2 >biglist : writes the contends of the list1 and list2 into the file called biglist respectively.
$ grep
this command is
used for searching files for specified
words or patterns. It is case sensitive.
$ grep science
science.txt : search science word in the science.txt file and print out each
line containing the word science.
$ grep –i
‘spinning top’ science.txt : search ’spinning top’ pattern in the science.txt
file with ignoring upper*lower case distinctionss
$ sort
this command is used for sorting alphabetically or numerically sorts a list.
$ sort
carrot
beetroot
artichoke
^D
artichoke
beetroot
carrot
$ sort < biglist ($ sort biglist ) : outputs the sorted list to the screen
$ sort < biglist > sortedlist : writes the output of the sorted list into the file called sortedlist