BASICS OF UNIX
COMMANDS
E
x INTRODUCTION TO
. UNIX AND BASIC
N UNIX COMMANDS
o
:
1
AIM:
To study about the basics of UNIX and Basic UNIX Commands.
UNIX:
It is a multi-user operating system. Developed at AT & T Bell
Industries, USA in 1969.
Ken Thomson along with Dennis Ritchie developed it from
MULTICS (Multiplexed Information and Computing Service) OS.
By1980, UNIX had been completely rewritten using C language.
LINUX:
It is similar to UNIX, which is created by Linus Torualds. All
UNIX commands works in Linux. Linux is a open source software.
The main feature of Linux is coexisting with other OS such as
windows and UNIX.
STRUCTURE OF A LINUXSYSTEM:
It consists of three parts.
a) UNIX kernel
b) Shells
c) Tools and Applications
UNIX KERNEL:
Kernel is the core of the UNIX OS. It controls all tasks,
schedule all Processes and carries out all the functions of
OS.
Decides when one programs tops and another starts.
SHELL:
Shell is the command interpreter in the UNIX OS. It
accepts command from the user and analyses and
interprets them
CONTENT:
Note: Syn->Syntax
a) date
–
used to
check the
date and
time Syn:
$date
F Purpose Examp Result
o le
r
m
a
t
+ To display only $date 06
% month +%m
m
+ To display month $date June
% name +%h
h
+ To display day of $date O1
% month +%d
d
+ To display last two $date 09
% digits of years +%y
y
+ To display hours $date 10
% +%H
H
+ To display minutes $date 45
% +%M
M
+ To display seconds $date 55
% +%S
S
b) cal
–
used
to
displ
ay
the
cale
ndar
Syn:
$cal
2
200
9
c)echo
–used to print the message on the screen.
Syn:$echo “text”
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 „ls‟ command is stored to disk file named „my list‟
d) lp
–
u
s
e
d
t
o
t
a
k
e
p
r
i
n
t
o
u
t
s
S
y
n
:
$
l
p
f
i
l
e
n
a
m
e
e) man
–used to provide manual help on every UNIX commands.
Syn:$man unix command
$man cat
f) 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
g)uptime
–tells you how long the computer has been running since its last reboot
or power-off.
Syn:$uptime
h) uname
–it displays the system information such as hardware platform, system
name and processor, OS type.
Syn:$uname–a
i)hostname
–
displays
and set
system
host
name
Syn:$
hostnam
e
j) bc
–stands for „best calculator‟
$bc $ $ $
bc
b b
c c
10/2 sca i s
*3 le b q
=1 a r
s t
e (
= 1
2 9
6
)
15 2.2 o 1
5+ b 4
1 a
s q
e u
= i
1 t
6
3.3 1
5 1
0
1
0
0
1
1
qu 8
it 9
2
7
5
1
0
1
0
Q
u
i
t
$bc $
b
c
-
l
for(i s
=1;i< c
3;i=i a
+1)I l
e
=
2
1 s
(
3
.
1
4
)
2 0
3
quit
FILE MANIPULATION COMMAND:
a) cat–this create, view and concatenate files.
Creation:
Syn:$cat>filename
Viewing:
Syn:$cat filename
Add text to an existing file:
Syn:$cat>>filename
Concatenate:
Syn:$catfile1file2>file3
$catfile1file2>>file3 (no over writing of file3)
b) grep–used to search a particular word or pat-
tern related to that word from the file. Syn:$grep
search word filename
Eg:$grep anu student
c) rm
–deletes a
file from
the file sys-
tem Syn:
$rm file-
name
d) touch–used to create a blank file.
Syn:$touch file names
e)
cp–
copies
the
files
or dir-
ector-
ies
Syn:
$cp-
sourc
e file
des-
tina-
tion
file
Eg:
$cp
stu-
dent
stud
f)
mv–to
rename
the file
or dir-
ectory
syn:
$mv old
file new
file
Eg:$mv–i student student list(-i prompt when overwrite)
g) cut–it cuts or pickup a given num-
ber of character or fields of the file. Syn:
$cut<option><filename>
Eg: $cut –c filename
$cut –c1-4 f5
$cut–f 3,6emp
$ cut –f 3-6 emp
-c cutting columns
-f cutting fields
h) head–displays10
lines from the head(top)of a
given file Syn:$head filename
Eg:$head student
To display the top two lines:
i) t
ail–dis-
plays last
10 lines
of the
file Syn:
$tail file-
name
Eg:$tail student
To display the bottom two lines;
Syn:$ tail -2 student
j) chmod–used to change
the permissions of a file or direct-
ory. Syn:$ch mod category
operation permis-
sion 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
Examples:
$chmodu-wx student
Removes write and execute permission for users
$ch modu+rw,g+rwstudent
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
C Operati P
a on e
t r
e m
g i
o s
r s
y i
o
n
u +assign r
– –
-
u remove r
s
e e
r a
s d
g =assign w
– –
absolu
g
r tely
w
o
u r
p i
t
o e
–
x
o
-
t
h e
e x
r e
s c
u
t
e
Syn: $wc –l filename
$wc –w filename
$wc–c filename