Practical 1
Aim: Study of Basic commands of Linux/UNIX.
Solution:
Test directory command
pwd : Print working Directory
pwd stands for ‘present working directory’. When you write pwd on prompt it will display the
current working directory.
Usage: Print working Directory name.
Syntax: pwd
Example:
mkdir : make directory
This command is used to create a new directory.
Syntax : mkdir directory name.
Usage : Creates new directory.
Example:
cd : Change Directory
This command is used to change the directory.
Usage : Change working directory.
Syntax : cd [directory]
Options:
_cd …Change working directory to home directory
_ cd ..…change working directory to parent directory
_ cd /user/lib…change working directory to absolute path/user/lib _ cd doc/letters…change
working directory to relative path doc/letters
Example:
Operating System 1
, 200090107080
rmdir : Remove Directory
Remove Directory. This command is used to remove a directory.
Usage : Creates new directory
Syntax : rmdir directory name
Example :
File commands :
cat:
It is used to create a new file. Press ctrl + C to indicate EOF.
Cat > file name - Creates new file.
Cat >> filename - Appends data to an existing file.
Usage: Display file contents, creates new file , or appends data to an existing file.
Syntax: Cat < file name - Displays file contents.
Example:
ls:
It lists all the filenames in alphabetical order which are present in the current directory.
Usage : List out contents of a directory.
Syntax: ls [directory]
Example:
Operating System 2
, 200090107080
cp :
Copy command, this command is used to copy a file.
Usage : Copies a file or group of files.
Options:
i: interactive copying (Asks before overwriting a destination file.)
r: recursive copying (It copies directory structure)
Syntax : cp [-irp ] file1 [file2… ] target
Example:
mv :
Move / Rename file, this command is used to rename files.
Usage : Renames a file, or moves a file or group of files.
Syntax : mv [-if] file [file2 …] target
Example :
rm :
Removes file , this command removes the given file or files supplied to it.
Usage : Removes files (deletes files)
Syntax : rm [-f] [-i] [-r] file
Options :
-i: interactive removal
-r: Recursive removal
-f: Forceful removal
Example:
Operating System 3
, 200090107080
wc:
It contains the number of lines, words and characters from the specified file or files.
Usage:
counts the number of characters , words or lines in a given input file. If the file is not given it
takes input from standard input.
Syntax: wc[file]
Options:
-l counts number of lines
-w counts number of words
-c counts number of characters
Example:
chmod:
chmod command is used to change the access mode of the file.
Usage:
change file permissionsIn Relative mode , the options first indicate whose access is to be
changed u (user,you), g (group), o(other), or a (all) ; then indicate the type of action +
(add),- (delete), or = (set); and then specify the access to be set r(read) and w(write/delete)
or x (execute).In absolute mode , three numbers represent the protections for the user ,
group and others ,Each number is a sum of 1 (for execute access), 2(for write/delete access)
and 4 (for read access).
Syntax: chmod [ugoa] [rwx] file (Relative Permission)
Example:
cmp :
compare the cmp utilities compares two files of any type and writes the result to the standard
o/p.
Syntax : cmp file1 file2
Usage : compares two files and given the location of the first mismatch.
Example :
Operating System 4