You are on page 1of 6

LINUX Assignments: 3

Section 1 :
1. Count the total number of words in file text1.
himanshu@ubuntu:~$ wc -w text1
11 text1
2. Display the system date in following format:
Today is Friday, 17 May 96
himanshu@ubuntu:~$ echo "Today is "`date +%A`" , "`date +%d` `date +%B` `date +%g`
Today is Tuesday , 09 October 12
3. Display the following text message on the monitor screen.
Deposited $100 to you account
himanshu@ubuntu:~$ echo -e "Deposited \$100 to you account"

Deposited $100 to you account

4.

Display the following message on the monitor.


The long listing of my home dir is
(Hint: Use ls l and pwd commands)
himanshu@ubuntu:~$ echo "The long listing of my home dir `pwd` is `ls -l`"
The long listing of my home dir /home/himanshu is total 300
drwxr-xr-x 3 himanshu himanshu 4096 2012-10-03 18:04 Desktop
drwxr-xr-x 2 himanshu himanshu 4096 2012-10-02 08:36 Documents
drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Downloads
-rw-r--r-- 1 himanshu himanshu 179 2012-08-28 14:50 examples.desktop
-rw-r--r-- 4 himanshu himanshu

29 2012-10-08 23:10 file2

-rw-r--r-- 4 himanshu himanshu

29 2012-10-08 23:10 file21

-rw-r--r-- 4 himanshu himanshu

29 2012-10-08 23:10 file22

-rw-r--r-- 4 himanshu himanshu

29 2012-10-08 23:10 file23

drwxr-xr-x 2 himanshu himanshu 4096 2012-10-08 20:20 him


-rw-r--r-- 1 himanshu himanshu

17 2012-08-28 14:58 him.sh

drwxr-xr-x 2 himanshu himanshu 4096 2012-10-08 20:20 his


-rw------- 1 himanshu himanshu 404 2012-09-29 21:07 hr11.sh
-rw-r--r-- 1 himanshu himanshu 601 2012-09-29 20:40 hr9.sh
-rw-r--r-- 1 himanshu himanshu 29583 2012-09-12 14:36 install.sh
-rw-r--r-- 1 himanshu himanshu 6366 2012-10-07 21:57 Linux assignment-I.docx
-rw-r--r-- 1 himanshu himanshu 56320 2012-09-25 10:14 Linux assignment-II.doc
-rw-r--r-- 1 himanshu himanshu 57856 2012-09-25 10:15 Linux assignment-III.doc
-rw-r--r-- 1 himanshu himanshu 59904 2012-09-25 10:16 Linux assignment-IV.doc
drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Music
drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Pictures
drwxr-xr-x 2 himanshu himanshu 4096 2012-10-07 21:37 play
drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Public
-rw-r--r-- 1 himanshu himanshu 172 2012-10-08 23:30 rim.sh
drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Templates
-rw-r--r-- 1 himanshu himanshu

53 2012-10-08 23:44 text1

drwxr-xr-x 2 himanshu himanshu 4096 2012-08-28 14:52 Videos


5. Display the name and count of the directories in the current directory.
himanshu@ubuntu:~$ find -type d -print; find -type d|wc -l

.
./.dbus
./.dbus/session-bus
./Templates
./play
./Downloads
./.compiz
./.compiz/session
./.gnome2
./.gnome2/file-roller
./.gnome2/keyrings
:
:
:
:
./.cache/software-center
./.cache/software-center/software-center-agent.db.tmp
./.cache/software-center/icons
./.cache/.fr-dotC8k

./.cache/.fr-dotC8k/Linux-lab-2012
266

6. Assign a value Black to var1 and then display the following message on the
terminal using this variable.
Black belt is associated with karate
himanshu@ubuntu:~$ var1=Black;echo "$var1 belt is associated with karate
"
Black belt is associated with karate

7. Create the file employee.txt having colon (: ) separated fields.


The fields of the record are: enumber, ename, eposition, esal, edoj, edept.
And now answer the following:
a. List all the employees along with a row number
himanshu@ubuntu:~$ cat file.txt|cut -f1-6|nl
1

101 : ram : manager : 70000 : 17 nov 2010 : 2

102 : shyam : clerk : 20000 : 1 jan 2000 : 4

103 : ghanshyam : sales manager : 30000 : 2 feb 2007 : 1

104 : parshuram : technician : 10000 : 23 mar 2011 : 6

105 : bhuleram : worker : 15000 : 24 jun 2004 : 5

106 : radheshyam : sales executive : 25000 : 2 jan 2012 : 1

107 : bhuleram : worker : 15000 : 24 jun 2004 : 5

108 : khoyeram : worker : 15000 : 24 jun 2004 : 5

109 : yaadram : worker : 16000 : 17 apr 2002 : 5

b. Sort the file as per the names


himanshu@ubuntu:~$ cat file.txt|sort -t ":" +1 -2
105 : bhuleram : worker : 15000 : 24 jun 2004 : 5
107 : bhuleram : worker : 15000 : 24 jun 2004 : 5
103 : ghanshyam : sales manager : 30000 : 2 feb 2007 : 1
108 : khoyeram : worker : 15000 : 24 jun 2004 : 5
104 : parshuram : technician : 10000 : 23 mar 2011 : 6
106 : radheshyam : sales executive : 25000 : 2 jan 2012 : 1
101 : ram : manager : 70000 : 17 nov 2010 : 2
102 : shyam : clerk : 20000 : 1 jan 2000 : 4
109 : yaadram : worker : 16000 : 17 apr 2002 : 5
c. List top three salaried employees
himanshu@ubuntu:~$ cat file.txt|sort -r -t ":" +3 -4|head -3
101 : ram : manager : 70000 : 17 nov 2010 : 2
103 : ghanshyam : sales manager : 30000 : 2 feb 2007 : 1
106 : radheshyam : sales executive : 25000 : 2 jan 2012 : 1
d. Remove duplicate records from the file
himanshu@ubuntu:~$ cat file.txt|unique file2.txt
e. List dept. no along with no. of employees working in each dept.

f. Sort the file in descending order of salary


himanshu@ubuntu:~$ cat file.txt|sort -r -t ":" +3 -4
101 : ram : manager : 70000 : 17 nov 2010 : 2
103 : ghanshyam : sales manager : 30000 : 2 feb 2007 : 1
106 : radheshyam : sales executive : 25000 : 2 jan 2012 : 1
102 : shyam : clerk : 20000 : 1 jan 2000 : 4
109 : yaadram : worker : 16000 : 17 apr 2002 : 5
15 : bhuleram : worker : 15000 : 24 jun 2004 : 5
108 : khoyeram : worker : 15000 : 24 jun 2004 : 5
105 : bhuleram : worker : 15000 : 24 jun 2004 : 5
104 : parshuram : technician : 10000 : 23 mar 2011 : 6

You might also like