You are on page 1of 6

Linux Assignment Ex-4

Archive the contents of your home directory using tar. Compress the tar file with gzip. Now uncompress and unarchive the .tar.gz file using cat, tar and gzip on one command line.

tar -cvf file1.tar /home/tejas gzip file1.tar gunzip fil1.tar.gz tar -xvf file1.tar tar -zcvf play.tar.gz play gzip -d play.tar.gz tar -xf play.tar cat play /hello.txt
1. Use find to compile a list of all directories in the system, redirecting the output so that the list of directories ends up in a file called directories.txt and the list of error messages ends up in a file called errors.txt. Answer: find / -type f ! directories.txt "!error.txt

2. ry the command sleep !. "hat does this command do#


Ans#er$ %his command delays of & seconds to the terminal. $. %un the command in the &ac'ground using (. Ans#er$ sleep 1& '

). %un sleep *! in the foreground, suspend it with Ctrlz and then put it into the
&ac'ground with &g. ype +o&s. ype ps. ,ring the +o& &ac' into the foreground with fg. Answer:

!. %un sleep *! in the &ac'ground using (, and then use 'ill to terminate the
process &y its +o& num&er. %epeat, except this time 'ill the process &y specifying its -./. Answer:

0. %un sleep *! in the &ac'ground using (, and then use 'ill to suspend the
process. Use &g to continue running the process. Answer: sleep 1& ' (ill sleep (ill -cont )4& // it*s command for resuming (illed processs

1. 2tartup a num&er of sleep 03 processes in the &ac'ground, and terminate them


all at the same time using the p'ill command. Answer:

8.

Use ps, w and top to show all processes that are executing.

9. Use ps ae4 to display the process hierarchy. 5oo' for the init process. 2ee if you can identify important system daemons. Can you also identify your shell and its su&processes#

*3 .Com&ine ps fae with grep to show all processes that you are executing, with the exception of the ps fae and grep commands. Ans#er$ ps -fae + tejas 11.2tart a sleep $33 process running in the &ac'ground. 5og off the server, and log &ac' in again. 5ist all the processes that you are running. "hat happened to your sleep process# Now repeat, except this time start &y running nohup sleep $33.

*2. 6ultiple +o&s can &e issued from the same command line using the operators 7,
(( and 88. ry com&ining the commands cat nonexistent and echo hello using each of these operators. %everse the order of the commands and try again. "hat are the rules a&out when the commands will &e executed# Answer: cd play cat hello.txt cd play '' cat hello.txt cd play ++ cat hello.txt 13."hat does the xargs command do# Can you com&ine it with find and grep to find yet another way of searching all files in the 9home su&directory tree for the word hello# Ans#er$ ,uild and execute command lines from standard input. find /home + xargs grep hello

14."hat does the cut command do# Can you use it together with w to produce a list of login names and C-U times corresponding to each active process# Can you now :all on the same command line; use sort and head or tail to find the user whose process is using the most C-U# Ans#er$ # + cut -c1-&-&.-./ ! ne#.txt + sort -r ne#.txt + tail -0 ne#.txt

You might also like