Unix Exercise 1

Embed Size (px)

DESCRIPTION

Unix Exercise 1

Citation preview

Course: Core Skills Module: Problem Solving Topic: UNIX - Basics Associate Supporting Materials Practice Set Log into UNIX system as per your user_id and password. 1. Change your password to your account. Answer : passwd username 2. Find out the directory where you are currently placed. Answer: pwd 3. Display the system date Answer : date +%F 4. Create a directory structure as follows under your home directory. HRD HR Answer : cd ~ mkdir HRD OFFICE cd HRD mkdir HR HRAG cd .. cd OFFICE mkdir TRNG FIN MFG 3. From your home directory list the directory structure that is under the root. Answer: ls 4. Create 3 empty files empty1, empty2 and empty3 under your home directory. Answer : touch empty1 empty2 empty3 5. List all the names of the files in your whole account that start with empty. Answer: ls empty* 6. Create a file text under HR and type a few lines. Display the contents of tex t. Answer: cat > text.txt Deepak Dileep Anusha Neelam Neeraj Sourav Ctrl + D cat text 7. Make a copy of text into another file copytext under TRNG. Answer: cp HRD/HR/text.txt OFFICE/TRNG/copytext.txt 8. Create a file matter under HRD and input a few sentences for it. Answer: cat > matter.txt hello everyone. My name is deepak. Ctrl + D 9. Combine the contents of the files text and matter into the file empty1. HRAG TRNG FIN OFFICE MFGAnswer: cat text matter > empty1 10. Compare text and copytext, matter and empty1 using cmp and comm. Answer : cmp HRD/HR.text OFFICE/TRNG/copytext [cmp compares two or more files and if they differ returns byte and line number at which the fisrt difference is reported] comm HRD/HR.text OFFICE/TRNG/copytext [compare two sorted files line by line] 11. Display the first 5 lines of the file empty1 Answer: head -5 empty1 12. Display the last 3 lines of the file empty1 Answer: tail -3 empty1 13. Create a link tmp under FIN for matter. Get inode numbers for both files? 14. Change the permissions for copytext to rwxrw_rw_. Answer: chmod 766 copytext 15. Delete the file text. Rename copytext to mytext. Answer: rm text mv copytext mytext 16. Copy mytext and matter under OFFICE directory and then move both files under MFG directory. 17. Copy OFFICE directory structure under HRAG directory in one shot. Answer: cp -R OFFICE HRD/HRAG 18. Test to walk upwards and downwards in mytext file using more command 19. List all the files created or modified during last 24 hours 20. Identify all empty files created earlier and delete them interactively. 21. List the directory structure under your home directory and then delete the s ame in one shot. 22. Use vi editor to create a file student under your home directory. Input 12 l ines for the name, age, roll number and sex. Use | as the field separator. Search some pattern using the editors internal commands. Answer: vi student23. (a) Use cut and paste commands to alter the field ordering in student. (b) Sort student: major key age, minor key sex; store sorted output in std. 24. Get all users currently logged on to your system with column headers for th e multi-column output and get the complete pathname of your terminal device. 25. Try the command: $ who | tee file1 | wc l | tee file2 How to use tee such that the list of the logged users as well as their count is displayed only on the terminal and the same is not stored in any file. References: Books: 1. UNIX Concepts & Applications, Sumitabha Das