BASICS OF UNIX COMMANDS
AIM:
To study the basic UNIX commands and their syntax.
COMMANDS:
Command is a Series of characters that invokes the shell and tells the UNIX
operating system to perform some operations.
CLASSIFICATION OF COMMANDS:
1. General Purpose Commands
2. Directory Commands
3. File Commands
4. Pattern Searching Commands
5. File Permission Commands
GENERAL PURPOSE COMMANDS:
1. COMMAND : date
PURPOSE : To display the current date and time
SYNTAX : $date
EXAMPLE : $date
2. COMMAND : cal
PURPOSE : To display the calendar
SYNTAX : $cal
EXAMPLE : $cal 1 2008
3. COMMAND : echo
PURPOSE : To display the message on the screen.
SYNTAX : $echo
EXAMPLE : $echo COMPUTER SCIENCE
4. COMMAND : who
PURPOSE : To show the users currently logged on.
SYNTAX : $who
EXAMPLE : $who
5. COMMAND : whoami
PURPOSE : To know in which terminal the user is currently logged on
SYNTAX : $whoami
EXAMPLE : $whoami
6. COMMAND : tty
PURPOSE : To report the name of the device the user is currently using for a
terminal
SYNTAX : $tty
EXAMPLE : $tty
7. COMMAND : df
PURPOSE : To show disk usage
SYNTAX : $df
EXAMPLE : $df
8. COMMAND : man
PURPOSE : It gives the online help to all commands with all options that a
command can support, followed by additional information
SYNTAX : $ man <command name>
EXAMPLE : $man ls
9. COMMAND : history
PURPOSE : To print the recently used commands
SYNTAX : $history
EXAMPLE : $history 5
10. COMMAND : clear
PURPOSE : To clear the screen
SYNTAX : $clear
EXAMPLE : $clear
DIRECTORY COMMANDS:
1. COMMAND : pwd
PURPOSE : To display the pathname of the current working directory
SYNTAX : $pwd
EXAMPLE : $pwd
2. COMMAND : mkdir
PURPOSE : To create a new Directory
SYNTAX : $mkdir <directory name>
EXAMPLE : $mkdir Oslab
3. COMMAND : cd
PURPOSE : To change from one directory (working) to another directory
specified by its arguments
SYNTAX : $ cd <directory name>
EXAMPLE : $ cd Oslab
NOTE : Without any argument, ‘cd’ changes to the home directory
4. COMMAND : rmdir
PURPOSE : To remove the existing directory
SYNTAX : $rmdir <directory name>
EXAMPLE : $rmdir Oslab
5. COMMAND : ls
PURPOSE : To list out the names of all files in the current working directory
SYNTAX : $ls
EXAMPLE : $ls
FILE COMMANDS
1. COMMAND : cat
a) PURPOSE : To create a new file
SYNTAX : $cat > <filename>
EXAMPLE : $cat > sample
UNIX <ctrl+D>
b) PURPOSE : To append the file contents
SYNTAX : $cat >> <filename>
EXAMPLE : $cat sample
Linux <ctrl+D>
c) PURPOSE : To display the file contents
SYNTAX : $cat <filename>
EXAMPLE : $cat sample
d) PURPOSE : To concatenate the multiple files into a single file
SYNTAX : $cat <file1> <file2> >> <file3>
EXAMPLE : $cat sample sample1 >> sample3
2. COMMAND : sort
PURPOSE : To sort the file contents in some particular order
SYNTAX : $sort <filename>
EXAMPLE : $sort sample
3. COMMAND : cp
PURPOSE : To copy a file to another file.
SYNTAX : $cp <source file> <destination file>
EXAMPLE : $cp sample sam
NOTE : Using ‘cp’ , we can copy file(s) to a directory and also copy a
directory to another directory.
4. COMMAND : mv
PURPOSE : To move the contents of file to another (that is, rename a file)
SYNTAX : $mv <source file> <destination file>
EXAMPLE : $ mv sam sam1
NOTE : Using ‘mv’, we can move file(s) to a directory and also move a
directory to another directory (that is, rename a directory).
5. COMMAND : rm
PURPOSE : To delete a file permanently
SYNTAX : $rm <filename>
EXAMPLE : $rm sam1
6. COMMAND : file
PURPOSE : To find the type of file present in that particular directory
SYNTAX : $file <filename>
EXAMPLE : $file sample1
NOTE : To find the type of all files in a directory, can use the syntax,
$file <directory name> / *
7. COMMAND : wc
PURPOSE : To count the number of lines, words and characters in a file
SYNTAX : $wc <filename>
EXAMPLE : $wc sample
PATTERN SEARCHING COMMANDS:
These commands are used to search for a particular pattern in one or more files and
display the result on the Standard Output.
1. COMMAND : grep (global search for regular expression and print)
PURPOSE : To search and display a line for a given word or given pattern
SYNTAX : $grep <pattern> <filename>
EXAMPLE : $grep i sample
NOTE : egrep ( extended version of grep) and grep (fast grep) are the other
pattern searching commands.
FILE PERMISSION COMMANDS:
Different modes or permissions associated with the file and directory in the UNIX
are:
(i) Owner Permissions
(ii) Group Permissions
(iii) Other Permissions
Symbolic method:
Access Class Operator Access Type
u (user) + (add access) r (read)
g (group) - (remove access) w (write)
o (other) = (set exact access) x (execute)
a (all: u, g, and o)
The actions that can be performed on a file or a directory by Owner, group or others are read
(4), write (2) and execute (1) permissions.
Absolute form
400 Read by owner
200 Write by owner
100 Execute by owner
NOTE: chmod is used to change the permissions of files or directories).
1. COMMAND : chmod 400
PURPOSE : To To sets permissions so that, user / owner can read, can't write and
can't execute
SYNTAX : $ chmod 400 <filename>
EXAMPLE : $ chmod 400 sample
2 COMMAND : chmod 200
PURPOSE : To sets permissions so that, user / owner can't read, can write and
can't execute
SYNTAX : $ chmod 200 <filename>
EXAMPLE : $ chmod 200 sample1
3 COMMAND : chmod 100
PURPOSE : To sets permissions so that, user / owner can't read, can't write and
can execute
SYNTAX : $ chmod 100 <filename>
EXAMPLE : $ chmod 100 sample1
RESULT:
Thus the basic UNIX commands were studied and executed successfully.