Upload
vkubendran
View
225
Download
0
Embed Size (px)
Citation preview
8/2/2019 Basic Unix Commands Final
1/9
Ex.No : BASIC UNIX COMMANDS
Date :
AIM:
To execute and implement the basic Shell UNIX commands.
DIRECTORY HANDLING COMMANDS
1.[root@localhost root]# mkdir arun //Creates a directory named arun
2.[root@localhost root]# cd arun //Enters into the directory arun
Example:
[root@localhost root]$ cd arun
[root@localhost arun]$
3.[root@localhost arun]# cd //Comes out of the directory arun[root@localhost root]
Example:
[root@localhost root]$ cd arun
[root@localhost arun]$ cd
[root@localhost root]$
4.[root@localhost root]# pwd //Shows the present working directory
Example:
[root@localhost root]$ pwd
/home/root
5.[root@localhost root]#rmdir arun //Used to remove directory arun
6.[root@localhost root]# ls //Shows the list of files & directories
Example:
[root@localhost root$ls
cse
it
ec
eee
mech
civil
8/2/2019 Basic Unix Commands Final
2/9
FILE HANDLING COMMANDS.
1.[root@localhost root]# cat > tksct //Creates a New file tksct
I studying B.E CSE.
2.[root@localhost root]# cat tksct //Opens the created file tksct"
I studying B.E CSE.
3.[root@localhost root]# cat >> tksct //Appends the details in the file tksct
I'm studying in Theni Kammavar Sangam College of Technology.
4.[root@localhost root]# cat tksct
I studying B.E CSE.
I'm studying in Theni Kammavar Sangam College of Technology.
5.[root@localhost root]$ cp data1 data2 //To create duplicate copies
[root@localhost root]$ cat data1
ab
c
d
[root@localhost root]$ cat data2
a
b
c
d
6.[root@localhost root]# rm data1 //Removes the file data1
rm: remove regular file `data1'? y
7. (i) [root@localhost root]# wc tksct //Shows the no. of lines, words & characters.
2 10 65 tksct
(ii) [root@localhost root]# wc -l tksct //Shows the no. of lines alone.
2 tksct
(iii) [root@localhost root]# wc -w tksct //Shows the no. of words alone.
10 tksct
(iv) [root@localhost root]# wc -c tksct //Shows the no. of characters alone.
65 tksct
8. [root@localhost root]$ mv data1 data5 //to move ordinary and directory files[root@localhost root]$ cat data5
a
b
c
d
[root@localhost root]$ cat data1
cat: data1: No such file or directory
8/2/2019 Basic Unix Commands Final
3/9
9.[root@localhost root]$ find data5 //To find a file
data5
PATTERN SEARCHING COMMANDS.
1.[root@localhost root]# grep m program //Prints the sentence with the letter m
My Name is sachin
I'm studying in Theni Kammavar Sangam College of Technology.
2.[root@localhost root]$ egrep "are|College" department // to search for the multiple pattern
we belong to Theni Kammavar Sangam College of Technology.
we are of cse students.
3.[root@localhost root]$ fgrep "stands for" student //to extract only the fixed string
CSE stands for Computer Science and Engineering.
GENERAL PURPOSE COMMANDS.
SIMPLE COMMANDS.
1.[root@localhost root]# cal //Prints the calendar if the present month
March 2006
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 2526 27 28 29 30 31
2.[root@localhost root]# date //Prints the current time.
Thu Mar 9 19:26:27 IST 2006
3.[root@localhost root$ man clear // Opens manual on clear
NAME
clear - clear the terminal screen
SYNOPSISclear
DESCRIPTION
clear clears your screen if this is possible. It looks in the environment for the
terminal type and then in the terminfo database to figure out how to clear the screen.
clear ignores any command-line parameters that may be present.
8/2/2019 Basic Unix Commands Final
4/9
4.[root@localhost root]# bc //Open the Binary Calculator
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This isfree software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
10 * 20
200
STATUS INFORMATION COMMANDS
1.[root@localhost root]$ who //to Display the list of users who are all currently logged into the system.
cse pts/4 Feb 23 23:56 (10.0.0.135)
cse pts/17 Feb 24 00:05 (10.0.0.221)
cse pts/10 Feb 24 00:09 (10.0.0.15)
cse pts/13 Feb 24 00:13 (10.0.0.180)
cse pts/1 Feb 24 00:14 (10.0.0.49)
cse pts/24 Feb 24 00:14 (10.0.0.6)
cse pts/3 Feb 24 00:17 (10.0.0.36)cse pts/30 Feb 24 00:19 (10.0.0.137)
2.[root@localhost root]# who am I //To displaysthe current user namecse pts/3 Feb 24 00:17 (10.0.0.36)
3.[root@localhost root]$ tty //It will retun the pathname with your terminal
/dev/pts/3
4.[root@localhost root]$ id //To Display the Numerical value that corresponda to you loginname.
uid=502(student) gid=502(cse) groups=502(root)
5.[root@localhost root]$ finger student // Gives you more Information about the User.
Login: student Name: (null)
Directory: /home/student Shell: /bin/bash
On since Thu Apr 19 09:38 (IST) on :0 (messages off)
On since Thu Apr 19 09:47 (IST) on pts/1 from :0.0
No mail.
No Plan.
COMMUNICATION COMMANDS
1.[root@localhost root]# wall Hai // To send message hai to all users there who arecurrently logged in.
Hai
2.[root@localhost root]$ mail cse // To send the textual messages from one user to another.
Subject: Hai.How are you.
All the best for your exams.
Have a nice day.
8/2/2019 Basic Unix Commands Final
5/9
3.[root@localhost cse$ mail // Read your mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/ece": 1 messages 1 new
a) >N 1 [email protected] Tue Feb 23 23:06 18/720 "Hai."&
Message 1:
From [email protected] Tue Feb 23 23:06:23 2010
Date: Tue, 23 Feb 2010 23:06:22 +0530
From: [email protected]
Subject: Hai.
How are you.Have you prepared for your exams.
ALL THE BEST FOR YOUR EXAMS.
Have a nice day.
b) & reply //To send the reply to the specified user
To: [email protected] [email protected]
Subject: Re: Hai.
ThanksCc: & ece
Unknown command: "ece"c)& exit //Exit from the mail
d)&type //Print the mail message
e)&delete //Delete from the mail box
INPUT AND OUTPUT REDIRECTION COMMANDS
1.[root@localhost root]$ date > a1
[root@localhost root]$ cat a1
Tue Feb 23 22:59:03 IST
2.[root@localhost root$< //To redirect the output of a command to a file.[ece@localhost ece]$ cat < department
CSE
EEE
SECURITY COMMANDS
1.[root@localhost root]$ ls -l // To list files & Directories in long format
total 3
-rw-rw-r-- 1 ece ece 30 Feb 9 23:47 lop
-rwx------ 1 ece ece 30 Feb 9 23:43 pal
-rw-rw-r-- 1 ece ece 65 Feb 23 23:16 science
2. [root@localhost root]$ chmod -u science //(-) denotes removing the permission
(u)denotes the user acess
[root@localhost root]$ ls -l
total 3
-rw-rw-r-- 1 ece ece 30 Feb 9 23:47 lop
-rwx------ 1 ece ece 30 Feb 9 23:43 pal
---------- 1 ece ece 65 Feb 23 23:16 science //showsMissing Permissions
8/2/2019 Basic Unix Commands Final
6/9
[root@server1 root]$ cat science
cat: science : Permission denied
3.[root@localhost root]$ chmod u+r,u+w science // (+)denotes assigningPermissions
(w) denotes writing permissions
(r)denotes reading permissions
[root@localhost root]$ ls -l
total 3
-rw-rw-r-- 1 ece ece 30 Feb 9 23:47 lop
-rwx------ 1 ece ece 30 Feb 9 23:43 pal
-rw------- 1 ece ece 65 Feb 23 23:16 science //the user now has reading writing permission
4.[root@server1 root]$ cat science
hi ! how r u ?
WILD CARD COMMANDS
1.[root@localhost root]$ ls m* //To representing any number of characters used in theprefix or suffix.[root@localhost root]$ ls
kanna mvj mvs student vikram
[root@localhost root]$ ls m*
mvj mvs
PIPES AND FILTERS COMMANDS
1.[root@localhost root]# more //To Displays the output page by page
[root@localhost root]$ ls | more
program1
program2program3
program4
program5
program6
program7
program8
program9
program10
program11
program12
program13program14
program15
program16
program17
program18
program19
--More-- //Press Enter to see the next page.
8/2/2019 Basic Unix Commands Final
7/9
2.[root@localhost root]# tr // It is used to translate characters taken from the standard input.
[root@localhost root]$ cat dept
cse
ece
eee
it
mech
[root@localhost root]$ cat dept|tr "[a-z]" "[A-Z]"
CSE
ECE
EEE
IT
MECH
[root@localhost root]$ cat sachin
arun
bala
cibidavid
elango
franklin
ganesh
harish
jegan
kalidos
lalprasanth
mahesh
nataraj
[root@localhost root]$ cat tendulkaryuvaraj
zaheer
3.[root@localhost root]$ head -5 sachin //To Display the First Five lines
arun
bala
cibi
david
elango
4.[root@localhost root]$ tail -5 sachin // To Display the Last Five linesjegan
kalidos
lalprasanth
mahesh
nataraj
8/2/2019 Basic Unix Commands Final
8/9
5.[root@localhost root]# sort sachin // Sorts in ascending order
arun
bala
cibi
david
elango
franklin
ganesh
harish
jegan
lalprasanth
mahesh
nataraj
6.[root@localhost root]# sort -r sachin //Sorts in descending order
nataraj
mahesh
lalprasanth
kalidosjegan
harish
ganesh
franklin
elango
david
cibi
bala
arun
7.[root@localhost root]# cut //To cut the selected fields.[root@localhost root]$ cut -c2 sachin
r
a
i
a
l
r
a
a
e
aa
a
a
8/2/2019 Basic Unix Commands Final
9/9
8.[root@localhost root]# paste //To paste the contenet from one to another file.
[root@localhost root]paste sachin tendulkar
arun yuvaraj
bala zaheer
cibi
david
elango
franklin
ganesh
harish
jegan
kalidos
lalprasanth
mahesh
nataraj
RESULT:
Thus the Basic Shell Commands were executed