EX.NO : 2.
a) UNIX COMMANDS
DATE :
AIM:
To illustrate about the UNIX Commands.
CONTENT:
Note: Syn -> Syntax
a) date
- used to check the data and time.
Syn: $date
Format Purpose Example Result
+%m To display only month $date+%m 06
+%h To display month name $date+%h December
+%d To display day of month $date+%d 03
+%y To display last two digits of years $date+%y 24
+%H To display hours $date+%H 09
+%M To display minutes $date+%M 11
+%S To display seconds $date+%S 59
b) cal
- used to display the calendar.
Syn: $cal 12 2024
c) echo
- used to print the message on the screen.
Syn: $echo “Hello World”
d) ls
- used to list the files. Your files are kept in a directory.
Syn: $lsls-s
All files (include files with prefix)
ls-l Lodetai (provide file statistics)
ls-t Order by size
ls-u Sort by access time (or show when last accessed together with –l)
ls-s Order by size
ls-r Reverse order
ls-f Mark directories with /, executable with *, symbolic links with @, local
sockets with =, named pipes(FIFOs) with ls-s Show file size.
ls-h ”Human Readable”, show file size in kilo bytes & mega bytes (h can be used
together with –l or 3 | P a g e )
ls[a-m]* List all the files whose name begin with alphabets from “a” to “m”.
ls[a]* List all the files whose name begins with “a” or “A”
Eg: $ls>my list Output of “Is” command is stored to disk file named “my list”.
e) lp
- used to take printouts.
Syn: $lp filename
f) man
- used to provide manual help on every UNIX commands.
Syn: $man unix command
$man cat
g) who & whoami
- it displays data about all users who have logged into the system currently.
The next command displays about current user only.
Syn: $who$whoami
h) uptime
- tells you how long the computer has been running since its last reboot or
power-off.
Syn: $uptime
i) uname
- it displays the system information such as hardware platform, system
name and processor, OS type.
Syn: $uname-a
j) hostname
- displays and set system host name.
Syn: $hostname
k) bc
- stands for ‘best calculator’
$bc $bc $bc $bc
10/2*3 scale=1 ibase=2 sqrt(196)
15 2.25+1 obase=16 14 quit
FILE MANIPULATION COMMANDS
a) cat
- this create, view and concatenate files.
Creation: Syn: $cat>filename
Viewing: Syn: $cat filename
Syn: $cat>>filename ( Add text to an existing file)
Concatenate: Syn: $catfile1file2>file3
$catfile1file2>>file3 (no over writing of file3)
b) grep
- used to search a particular word or pattern related to that word from the
file.
Syn: $grep search word filename ( Eg: $grep anu student)
c) rm
- deletes a file from the file system.
Syn: $rm filename
d) touch
- used to create a blank file.
Syn: $touch file names
e) cp
- copies the files or directories.
Syn: $cpsource file destination file ( Eg: $cp student stud)
f) mv
- to rename the file or directory.
Syn: $mv old file new file ( Eg: $mv-I student student list(-I prompt when overwrite)
g) cut
- it cuts or pickup a given number of character or fields of the file.
Syn: $cut
Eg: $cut-c filename $cut-f 3,6emp
$cut-c1-10emp $cut-f 3-6 emp
-c cutting columns
-f cutting fields
h) head
- displays 10 lines from the head(top) of a given file.
Syn: $head filename
Eg: $head student
$head-2 student (To display the top two lines)
i) tail
- displays last 10 lines of the file.
Syn: $tail filename
Eg: $tail student
$tail-2 student (To display the bottom two lines)
j) chmod
- used to change the permissions of a file or directory.
Syn: $chmod category operation permission file
where,
Category - is the user type.
Operation - is used to assign or remove permission.
Permission - is the type of permission.
File - are used to assign or remove permission all.
Eg: $chmodu-wx student (Remove write and execute permission for users.)
$chmodu-rw,g+rw student (Assigns read and write permission for users and
groups.)
$chmodg=rwx student (Assigns absolute permission for groups of all read, write
and execute permissions.)
k) wc
- It counts the number of lines, words, character in a specified file(s) with
the options as –l, -w, -c.
Category Operation Permission
u- users + assign r- read
g- group - remove w- write
o- others = assign absolutely x- execute
RESULT :
Thus the Illustration of UNIX Commands are Studied.