2.unix Commands
2.unix Commands
Aim:
To study the basic concepts of Unix Operating system.
Introduction:
Unix is a multi user OS which means it allows several users to work the system at the
same time. Unix differs from other operating systems in several ways:
i) It is multiuser
ii) It is multi-tasking
iii) It very rarely crashes
iv) It is like a toolkit. It contains many small programs and tools, that can be used
together to solve complex problems.
Features of Unix:
1. Unix is a registered trademark of AT & T’s Unix system laboratory and it was originally
developed on a Digital Equipment corporation in 1969 by Ken Thompson and Dennis
Ritche.
2
Ex.No:2 BASIC UNIX COMMANDS
Aim:
To study the logic basic UNIX command.
Login:
Click ‘start’ button in the desktop. Then click on the ‘Run’ command and then enter
‘telnet’.Then give the value of the port address.
Password:*********
Logout:
To logout from UNIX type’exit/ctrl+d’
COMMAND: echo
PURPOSE : This command is used to display the given text.
SYNTAX : $echo<text>
COMMAND: man
PURPOSE : This command displays help menu(manual page).
SYNTAX : $man
COMMAND: date
PURPOSE : This command is used to display the date and time.
SYNTAX : $date
COMMAND: cal
PURPOSE : This command is used to display the month or year calendar.
SYNTAX : $cal<month/year>
COMMAND: spell
PURPOSE : To check spelling in a given text file.
SYNTAX : $spell filename
3
COMMAND: sleep
PURPOSE : This command is used to pause the system for some seconds (or) minutes
(or) days.
SYNTAX : $sleep<number><seconds/minutes/hours/days>
COMMAND : who
PURPOSE : ‘who’ is used to display all users working in the network.
SYNTAX : $who
COMMAND : who am i
PURPOSE : This command is used to display the current working user.
SYNTAX : $who am i
COMMAND : clear
PURPOSE : This command is used to clear the screen.
SYNTAX : $clear
COMMAND : time
PURPOSE : This command is used to figure out the time taken to execute the
Command.
SYNTAX : $time command
Directory Commands
COMMAND : pwd
PURPOSE : ‘pwd’ is ‘print working directory’ and it gives the current working
Directory.
SYNTAX : $pwd
COMMAND : mkdir
PURPOSE : mkdir is ‘make directory’ and is used to create a new directory.
SYNTAX : $mkdir dirname
COMMAND : rmdir
PURPOSE : rmdir is ‘remove directory’ and it is used to remove any directory.
(empty directory only)
SYNTAX : $rmdir dirname
COMMAND : cd
PURPOSE : cd is ‘change directory’and is used to change directory.
SYNTAX : $cd dirname
4
OPTIONS :
.. Previous directory
\ return to root.
COMMAND : ls
PURPOSE : ls is the ‘list’ command ,it will list all files in a particular directory.
SYNTAX : $ls {name},where name refers to file name.
OPTIONS :
- a lists all contents including hidden files.
- l lists all contents of directory in long form.
- d lists only the name of the directory and not the contents.
- m lists the contents across the screen,separated by comma.
COMMAND : finger
PURPOSE : To get all directories and all the users.
SYNTAX : $finger
File Commands:
COMMAND : cat
PURPOSE : This command is used to create a new file or to display the file
Contentsand this command can be used to merge two or more files.
^d
SYNTAX :(to merge two or more files)
$cat filename1 filename2 >filename3.
COMMAND : cp
PURPOSE : This command is used to copy file to another file.
SYNTAX : $cp filename 1 filename 2(here file 1 is copied to file 2)
COMMAND : rm
PURPOSE : This command is used to remove files.
SYNTAX : $rm filename
5
OPTIONS :
- f remove file without verification with user.
- I remove file after verification from user.
COMMAND : mv
PURPOSE : Moves a file or multiple files into another directoyry or a new name in
the current directory.
SYNTAX : $mv filename 1filename 2
OPTIONS :
- f moves file(s) without checking for verification in case of over writing.
- i prompts if the action overwrite existing file.
COMMAND : touch
PURPOSE : This command is used to create an empty file
SYNTAX : $touch filename
COMMAND : wc
PURPOSE : This command display number of characters in a file(bytes, words, lines)
SYNTAX : $wc filename
OPTIONS
- l displays number of lines
- w displays number of words.
- c displays number of characters.
COMMAND : head
PURPOSE : This command is used to display first ten lines of a file.
SYNTAX : $head filename
OPTIONS :
- n display first n numbers of lines in files
COMMAND : tail
PURPOSE : This command is used to display last ten lines of a file.
SYNTAX : $tail filename
OPTTIONS
- n display last n numbers of lines in files
COMMAND : more
PURPOSE : This command is used to view a file page by page.
6
SYNTAX : $more filename
COMMAND : sort
PURPOSE : This command is used to sort one or more files m ASCII format.It can be
Used to merge file that has been already sorted.
SYNTAX : $sort option filename
OPTIONS :
- r sort in reverse order
- d sort in dictionary order
COMMAND : find
PURPOSE : It is used to locate one or more files or directories that satisfies some
Specified char in the path specified
SYNTAX : $ find <search-path>
OPTIONS :
- name find file with specified name
- size find file with specified size
COMMAND : cmp
PURPOSE : It is often required to know whether two files are identical. Command is
Issued to accomplish this. It needs two file names at segments.
SYNTAX : $cmp file1 file2
COMMAND : tr
PURPOSE : It translates the characters in a file.It takes two arguments and translates
Each member of the first set by the equivalent member of the second set.
SYNTAX : $tr character set1 character set2<file
Filter Commands:
COMMAND : cut
PURPOSE : It is used to cut specified fields(or) column from each line of one or more
Files.
SYNTAX : $cut option file
OPTIONS:
- c characters list specifies the list of characters to be cut.
- f ,field list specifies the list of fields to be cut
- b, bit list specifies the list of bits to be cut.
COMMAND : grep
7
PURPOSE : It is an acronym to globally search a regular expression and print it.
SYNTAX : $grep pattern filename.
Redirection Symbols:
<Redirection of input
Redirect the input for a command to come from a file on your system disk instead of from your
terminal keyboard.
Command < filename
Cat < poem
>Redirection of output
It is used to redirect output to a file on your system.If file not exist, the file created by shell.
If file is exist we shall overwrite its contents in
Eg date > date.now
>> Tells the shell to redirect the standard output to the end of file.
Eg date >> date.now
SYNTAX :
i) cat file1>file 2
Output of cat is to set to file2 and not to standard output .It takes file to
automatically if not existing.
ii) who>file
who>>file
COMMAND : piping(|)
PURPOSE : It can be used to join commands. The output of one command can be sent as
input to another one.
SYNTAX : $ who | sort
Process Commands:
COMMAND : ps
PURPOSE : Each process is given an unique identification number. The second column
display the name of the terminal from which the process is being controlled.