lab-sheet-6
lab-sheet-6
Problem-Sheet#6
Some more Linux commands included here related to redirec on, filters,process handling,informa on,
transla on,archiving, compression and encryp on etc.
Files given in sfolder-6 folder are- infa,in ,infc,fsleep are executable files(In executable files- a infinite loop or
sleep for specific dura on- are implemented)
Q0.
(It prompts to enter current password therea er new password and finally confirm new password)
(create 8 char password as given – first two digits , next one special char, next one lower one upper char, next
one special char and next one char and one digit)
(Assuming files referred in this sheet are in current path. If a file is not in current path then give its
appropriate path. For example path of infa from your UHD is- labsheet/sfolder-6/infa )
Q1.
ii. Count lines,words and characters of sorted output of 'ls' [ls | sort | wc]
iii. Count number of lines of sorted output of 'ls' [ls | sort | wc -l]
v. Sort the output of 'ls' , display it and also save in 'file61' [ls | sort | tee file61 ]
vi. Copy a file to mul ple(three) des na on(files), do not display the output on the screen [tee <file61
file{a..c}>/dev/null].
(ouput of file61 is goes to /dev/null instead screen and copies file1 to filea,fileb and filec )
aa
bb
cc
ee
ffa
ffc
dd
[mkdir -p aa/{bb,cc/ee/ff{a,b,c},dd} creates folders with ffa, and ffc as sibling inside ee. Sub folders bb,cc and
dd are sibling,inside folder aa]
Q2 redirec on
i. Display 'file61' [cat <file61] (same can be displayed using cat -n file61)
ii. Copy 'file61' to 'file62' using cat using both redirec on command [cat <file61 >file62]
iii. Run 'ls', 'tree' and 'date' commands as foreground process in sequence (type these commands separated by
";" a er last command press ENTER) [ls ; tree ; date]
iv. Run two commands with AND condi on- {if first valid command then only run second command} [hate &&
date]
v. Repeat Q2(v) with redirec ng standard error to file err1 [hate 2> err1]
vi. Run two commands with OR condi on- {execute a command if any of these commands valid} [hate || date]
vii. Run 'tree' and 'ls' command in background (send output to /dev/null) and date in foreground
[tree>/dev/null& ls>/dev/null& date;jobs]
Q3. (Give path of executable file 'infa' as labsheet/sfolder-6/infa OR ./infa in case these files copied in your
current directory)
Display processes [jobs] ,display process status using [ps -l] (T flags for stoped process)
ii. Repeat Q3(i) problem with three programms 'infa', 'in ' and 'infc' (run each in background) [./infa& ./in &
./infc&]
Display processes in current session [jobs]. To display stopped processes [jobs -s]
iv. Terminate a background (stopped or running) process [ kill job-number] or [kill pid-of-the-process-to-be-
terminated]
v. Execute a command using 'exec' and terminate the bash [exec ls]
vi. Execute a command using 'exec' in background (it will not terminate the bash) [exec sleep 15& ps -l]
Q4.
i. Display real me(turnaround)taken by following commands- 'date', 'ls' and 'fsleep' [ me date ; me ls ; me
./fsleep]
ii. Sleep the shell for 10 seconds and display real me [echo "i am sleeping" ; me sleep 10] (CTRL-C will wakeup
the shell)
iii. Display message "my home directory" [echo "my home directory" $HOME]
iv. Append a line in 'file51' using echo [echo "last line added using echo">>file61]
vi. Add your UHD at the beginning of PATH and verify it[ export PATH=/home/os23/23osxxxx:$PATH]
viii Display environmental variables [env] // ( 'printenv' command gives same effect)
x. Change color of prompt with style[PS1="\[\033[01;37m\]\u@h"] ( 30m to 37m gives different color,00 to 07
gives effect)
Q5.
ii. Note down me stamp of the 'file62' [ls -l] then update me stamp of the file61 [touch file62]
iii. Display contents of 'lab-sheet-2-v2' [ more lab-sheet-2-v2] , display next page (press space bar , press q to
return to shell)
iv. Display contents of 'lab-sheet-2-v2' [less lab-sheet-2-v2) , display next 7 lines [7j], previous 3 lines [3k], go to
line with "minix "[/minix] , quit less u lity [q ]
viii. Sort the file 'file61' in reverse order and display [sort -r file61]
ix. Sort the file 'file61' without case sensi ve and output to 'file6s' [sort -f file51 -o file6s]
x. Create a file 'file63' having sorted tree output [tree | sort -o file63]
Q6
ii. Split the file 'lab-sheet-2-file' in small sized(1000 Bytes) files(with filename beginning with 'zoo') [ split -
b1000 qsheet/lab-sheet-2-file zoo ]
iii. Display 'zooaa', 'zooab' and 'zooac' [cat zooaa zooab zooac]
iv. Concatenate files having star ng name 'zoo' to 'file64' [ cat zoo* > file64 ]
v. Display lines and linenumber having word 'Linus' in 'lab-sheet-2-file' [grep -n Linus lab-sheet-2-file]
vi. Display output of 'tree' of parent folder of UHD having character 'c' [tree ../ | grep c]
vii. Display the Linux process [top]; press q to terminate, Note down PR (priority) and NI (nice value)
viii. Repeat Q5(vii) with lower priority [nice -n 10 top]. Compare the output of vii and viii.
Q7.
ia. Display all processes (or first few) with details [ps -el] or [ps -el | head]
iii. Sleep shell for 10 seconds and display process tree [echo "i am sleeping"],[ me sleep 10& pstree]
iv. Dynamically display processes status (press q to return back to shell) [top]
ix. Translate(encrypt based on rotate13) keyboard input [cat |tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]' ]
(type a word or sentence , press enter. It encrypts input based on rotate13. use CTRL-C to stop )
x. Change lower to upper case of characters in 'file61' [tr '[a-z]' '[A-Z]' < file61]
xi. Generate four random pa ern of eight characters from given pa ern
[cat /dev/urandom| tr -dc 'a-zA-Z0-9' | fold -w 8| head -n 4 ]
xii. Generate four random pa ern of twelve characters using your name, DOB and special chars
Q8
iii. Create a folder 'uhd' and cd to 'uhd'. Extract the files from 'draa.tar' in folder 'uhd' [tar xf ../draa.tar ]
v. Delete 'file4h' from 'draa.tar' [tar f draa.tar –-delete file4h] (use appropriate path for file4h)
vi. Delete contents of folder 'drbc' from 'draa.tar' [tar f draa.tar –-delete drba/drbb/drbc/*]
vii. List the files in 'draa.tar' [tar draa.tar] and confirm Q8(vi)
viii. Create archive of folder 'drba' using gzip compression algo [tar czf drba.tar.gz drba]
ix. Compress files of folder 'drca' recursively with gzip [gzip -r drca] (does not affects symbolic files)
x1i. Repeat Q7(ix) with low compression [gzip -r -1 drca] ;verify with 'ls -l' ; uncompress files
xi1i. Repeat Q7(ix) with high compression [gzip -r -9 drca] ;verify with 'ls -l' ; uncompress files
xiv. Compress folder 'draa' and encrypt it with password (it prompts to enter password) [zip -r -e draa.zip draa]
Share public key with others. Others can encrypt message using your public key. Only you can decrypt this
message using your private key. You can encrypt a message using your friend(s) public key(s). Only the person
whose public key is used for encryp on can dectrypt the message using his/her private key.
These keys are stored in keyring. The private key is protected by passphrase. Whenever you use private key,it
prompts you to enter passphrase to validate yourself. Never share private key.
i. Create public key and private key pair using gngpg applica on
(provide your emailid [email protected] ,dura on 1 yr of validity of the key and password for protec ng
your private key)
[gpg --gen-key ]
iv. Send your public key to others (put in /tmp) and retrieve others public key in your current directory
vii. Write a message in a text (xxxx1.txt) file and encrypt this for one of classmate whose public key in your
keyring
[ cat >xxx.txt ......... crtl+d (create text file having message for others)
gpg --encrypt --armor --recipient friendmailid xxxx1.txt (friendmailid is iden fies the respec ve public key )
viii. Encrypt your text message for more than one classmates whose public key in your keyring
[gpg --encrypt --armor --recipient friendmailid1 --recipient friendmailid2 xxxx1.txt.asc] (repeat --recipient for
as many friends)
ix. Send the encrypted message to others (put in /tmp) and retrieve encrypted message(s) in your current
directory
x. Try to decrypt the others message.(IF it is encrypted for you, you will able to read)
[cp /tmp/someother.asc . ](get the encrypted text file sent by others for others , it may or not may be you)
[gpg --decrypt somexxxx.txt.asc] (if this file is encrypted for you, it prompts for passpharse to use your
privatekey)
[ cat somexxxx.txt ] (read the decrypted file. this message is for you)