Sie sind auf Seite 1von 6

UNIX COMMANDS

SESSION:II BATCH –I DATE:03.01.11

1. Find out how many separate inodes are represented by files


[Note: before that create two files and also links for that file, so that there will be same
inodes of files.]
something to do with ls -i and then uniq

2. Sort in reverse order the contents of the infile1 and infile 2 placing the output in outfile
and using the first character of the second field as the sort key.
Ans : sort -r -o outfile -k 2.1,2.2 infile1 infile2

3. How will you count the number of empty lines in a file


grep ' ' manu.txt | wc -l

4. Provide a numbered listing of all files in your directory in reverse order and print from
7th line
ls -r | nl > new.txt | head -n7 new.txt
| tail -6 new.txt
7 kaushik

8 KAUSHI

9 fork.c~

10 fork.c

11 Beej's Guide to UNIX IPC.pdf

12 a.out

5. Display all lines in a file which contain the word “World all occurrences like
world,World,WOrld,WORld….ignore case option” from a file. Report is not allowed.

grep -i world world.txt

this World

this world
WoRld

worlD

WORLD

woRLd

6. Delete all but non-alphanumeric characters in a file.


cat alpnum.txt |tr -d [:alnum:]

=#$%^&*()

7. Do the following global searches and replacements:


a. Change the full stops with semicolon. i/p :uytfi8r7=656..5tyuygioupw02#$
%^&*()..

cat alpnum.txt | tr [=.=] \;

uytfi8r7=656;;5tyuygioupw02#$%^&*();;

b. Change all occurrences of word given by user to upper case.


sed -e 's/[wW][oO][rR][lL][dD]/WORLD/g' world.txt

this WORLD

this WORLD

tead

worlli

WORLD

WORLD

WORLD

WORLD
Create a file emp with name,ssn,age,salary,dept.

8. Answer the following with appropriate filters:


i. Sort the emp file based on dept and display the name of the employee and
the department
cat emp.txt | sort -k 5

harsha 8978 21 5000 market

kiran 8790 20 4000 market

kushal 9790 23 8990 services

kushal 9790 23 8990 services

ii. List the employees who earn between 4000 and 6000
iii. Locate only the marketing dept employees
grep market emp.txt

harsha 8978 21 5000 market

kiran 8790 20 4000 market

iv. list the duplicated records of the file with the frequency of occurrence and
dump them into a file called dup.(use uniq and sort filter)
cat emp.txt| sort -k 5|uniq -f 1 >dup.txt

kushal 9790 23 8990 services

v. Sort the file on the employee codes and extract the basic and names of the
non-duplicated lines
cat emp.txt| sort -k 2|uniq -f 1 |cut -f 4,1 -d " "

kiran 4000

harsha 5000

kushal 8990
9. Frame a grep command which locates the people from emp database having the same
month of birth as the current month.
grep -i `date +%b` emp.txt

10. kushal 9790 23 8990 services 19-jan-90

kiran 8790 20 4000 market 20-jan-90

11. From emp file retrieve the records with designation as director and salary > 7600.

12. Devise a pipeline to locate the user who logged in first (assuming they all logged in the
same month) and extract only the log in id.
who | sort -k 4 | head -n 1 |cut -f 1 -d “ “

13. Write a command sequence which displays every file in the system having a size larger
than 100 KB. Ans. find -size +100k

/oslab prhs/os-labwork.pdf

./oslab prhs/New folder/prince02(www.songs.pk).mp3

./oslab prhs/New folder/prince01(www.songs.pk).mp3

./oslab prhs/New folder/kaushik tikt.doc

./oslab prhs/full ftp/my html/Winter.jpg

./oslab prhs/full ftp/SDM LAB_EVAL 1/E-Ticketing.doc

./oslab prhs/full ftp/HTML_assignment/37.jpg

./oslab prhs/full ftp/HTML_assignment/tp.jpg

./oslab prhs/full ftp/HTML_assignment/25.jpg

./oslab prhs/full ftp/HTML_assignment/2.jpg

./oslab prhs/full ftp/HTML_assignment/tp2.jpg

./oslab prhs/full ftp/HTML_assignment/002.JPG

./oslab prhs/full ftp/HTML_assignment/13.jpg

./oslab prhs/full ftp/HTML_assignment/tp3.jpg


./oslab prhs/full ftp/HTML_assignment/tp4.jpg

./oslab prhs/full ftp/HTML_assignment/mypic.JPG

./oslab prhs/full ftp/sdm lab(13-1-10)/sat1-Ghosh.pdf

./packages/aptoncd-20090906-CD1.iso

./packages/aptoncd-20090713-CD1.iso

./packages/aptoncd-20091004-CD1.iso

./packages/aptoncd-20091008-CD1.iso

./packages/aptoncd-20090710-DVD1.iso

./packages/aptoncd-20091012-CD1.iso

./kaushik/Exploit writing tutorial part 1 Stack Based Overflows Peter Van


Eeckhoutte'sBlog.htm

/kaushik/Eploit writing tutorial part 1 Stack Based Overflows Peter Van Eeckhoutte's
Blog_files/image50_thumb.png

./Beej's Guide to UNIX IPC.pdf

14. Use a filter to extract file access permission’s and file name and paste it in another file
logevent.

find packages -printf "%f:%m\n" > logevent

packages:700

aptoncd-20090906-CD1.iso:700

aptoncd-20090713-CD1.iso:700

aptoncd-20091004-CD1.iso:700

aptoncd-20091008-CD1.iso:700

aptoncd-20090710-DVD1.iso:700

aptoncd-20091012-CD1.iso:700
15. Write a filter to remove all colon’s in a file and display it.
cat alpnum.txt | tr -d [=:=]

uytfi8r7=656..5tyuygioupw02#$%^&*()..98709uy7tgiu8

16. Write a tool to check whether the number of open braces are equal to number of close
braces in a C program file Write a filter to remove all colon’s in a file and display it.

Das könnte Ihnen auch gefallen