Unix Manual

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Unix Manual as PDF for free.

More details

  • Words: 924
  • Pages: 3
SWARNABHARATHI COLLEGE OF ENGINEERING,KHAMMAM. UNIX LAB MANUAL Prepared by Mr. G.Hari Krishna & B. Srinivas WEEK I Session I 1) log into the system a) use the login command to log into system. It will ask for username and password. 2) use vi editor to create a file name as myfile.txt which contains some text. a) use vi command to create a file. Syntax: vi filename Ex: vi myfile.txt now press enter Press I button to goto insert mode, now enter the data. 3) If any errors present then modify by using the keyboard. 4) Save the file a) Now press esc button to change the text mode b) Now press :x or wq which is for saving file. 5) to logout terminal a) use the command exit Session II 1) log into the system a) use the login command to log into system. It will ask for username and password. 2) open the file created in session I a) vi myfile.txt 3) add some text a) use I button for insert mode, now add some new text. 4) delete some text a) now press esc and use the x button to delete the text. 5) change some text a) press insert button for replace mode and change some text. 6) to logout system a) use init 0 to shutdown the system. WEEK II 1) log into the system a) use the login command to log into system. It will ask for username and password. 2) use cat command to create a file mytable contain the data. Syntax cat > filename a) cat > mytable 1425 ravi 15.65 4320 ramu 26.27 6830 sita 36.15 1450 raju 21.86 For gaps use the tab button 3) display the text in mytable a) cat mytable 4) correct any errors. a) use vi command to open the file mytable and correct any errors. 5) sort the file a) use the sort command to sort the file and save the contents in to new file.

b) The command is sort mytable > nmytable, here the contents of mytable is sorted and stores in the new file nmytable. 6) print the file mytable. a) Use the lp command to print the file. The command is lp mytable. 7) print the file nmytable. a) Use lp nmytable to print the new file. 8) logout into the system. a) use init 0 to shutdown the system. WEEK 3 SESSION I 1) log into the system a) use the login command to log into system. It will ask for username and password. 2) To display the login shell a) type echo $0 to see the present login shell. 3) To verify the file. a) cat /etc/passwd it will show the shell type. 4) To save the result of who command and display by using more a) Type who > myfile1 it will move the result to myfile1. b) Type more myfile1 it will display the contents of myfile1 in screen wise if it contains more than 15 lines. 5) To display who on the screen and date to a file a) Type who; date > myfile2 it will show the user on the screen and stores the result of date onto the file myfile2. a) Type more myfile2 to display the contents of myfile2. SESSION II 1) write a sed command to delete the first character in each line of a file. a. Write a script in the file del.sed as follows i. s/^[a-z]/ /g and save the file. ii. Now give the command sed –f del.sed hari now it will delete the first character in each line. 2) To delete the last character in each line of a file. a. Write a script in the file del.sed as follows i. s/[a-z]$/ /g or s/[^$]$/ / and save the file. ii. Now give the command sed –f del.sed hari now it will delete the last character in each line. 3) To swap the first and second lines of a file. a. Type vi sw.sed h n G p after save the file. b. now give the command sed –f sw.sed hari now it will swap the line 1 with line 2 in the file. Here h copies, n reads, G appends, p only fisrt line. WEEK 4 1) to display the user home directory a. fisrt give the command tail -3 /etc/passwd > usnam now it will copy the last 3 lines of the present users in to the file usnam. b. Now give the command awk ‘{print $6 ,$7}’ usnam now it will print the home directory for each user. 2) to display how many lines contain the given word. a. Write a script file as follows

Clear Echo “enter the file name” Read ha Echo “enter the text” Read sr X= `grep –c “$sr” $ha` // ` ` is for command execution Echo $x. 3) to print the text in which the given word is present using awk. a. Type the command awk “/ text/{print}” filename. i. Ex awk “/how/{print}” xx it will print the lines contain how. WEEK 5 1) write a shell script to accept a file name in the command line argument and find the given name is file or directory. a) vi x clear if [ -f $1 ] ; then echo “it is a file” else if [ -d $1 ] ; then echo “it is a directory” else echo “others” fi fi to run the program use sh filename argument. Ex sh x hari it will check the given hari is a file or directory.

Related Documents