Você está na página 1de 6

ANNA UNIVERSITY PRACTICAL EXAMINATIONS (MAY-JUNE 2010) GE2155 COMPUTER PRACTICE LABORATORY II QUESTION SET 1, 2, AND 3 1. a.

. Write and execute the following UNIX commands (i) Create a file. student@linuxmint ~ $ cat > test My first file in LINUX Linux is a multi-user OS (ii) Display only the first two characters of all the lines from a file. student@linuxmint ~ $ cut -c1-2 test My Li (iii) Convert the lower case to uppercase. student@linuxmint ~ $ tr "[:lower:]" "[:upper:]" <test MY FIRST FILE IN LINUX LINUX IS A MULTI-USER OS (iv) Combine two strings. student@linuxmint ~ $ n=narayana student@linuxmint ~ $ s=swamy student@linuxmint ~ $ echo $n$s narayanaswamy (v) Display the file contents in descending order. student@linuxmint ~ $ cat >1.txt narayana vimala kamala student@linuxmint ~ $ sort -r 1.txt vimala narayana kamala 2. a. Write and execute the following UNIX commands (i) Create two files with the name of name.txt, which contain only names, and reg.txt with the content of register number respectively. student@linuxmint ~ $ cat > name.txt Narayana Vimala student@linuxmint ~ $ cat > reg.txt 1050092 1050093 Page 1 of 6 College

UNIX Commands (ii) Combine the two files in the form of register number followed by name student@linuxmint ~ $ paste reg.txt name.txt 1050092 Narayana 1050093 Vimala (iii) Sort the two files in ascending order student@linuxmint ~ $ sort name.txt Narayana Vimala student@linuxmint ~ $ sort reg.txt 1050092 1050093 (iv) Count the number of lines in the files student@linuxmint ~ $ wc -l name.txt 2 name.txt student@linuxmint ~ $ wc -l reg.txt 2 reg.txt (v) Rename the two files. student@linuxmint ~ $ mv -i reg.txt reg1.txt student@linuxmint ~ $ mv -i name.txt name1.txt 3. a. Write and execute the following UNIX commands (i) Create two files. student@linuxmint ~ $ cat > a1 Welcome to student@linuxmint ~ $ cat > a2 UNIX Operating System (ii) Combine the two files. student@linuxmint ~ $ cat a2 >> a1 student@linuxmint ~ $ cat a1 Welcome to UNIX Operating System (iii) Search a specific word from any one of the file. student@linuxmint ~ $ grep 'UNIX' a1 UNIX Operating System (iv) Search a specific file from a directory. student@linuxmint ~ $ ls 1.txt a2 Downloads name1.txt prince.zip Templates 2.txt asd final.txt name.txt Public test 3.txt cam.txt mmm.odt Pictures q.txt Videos 5.txt Desktop Music prince 19.9.11 reg1.txt w.txt a1 Documents naasa.c prince 19.9.11.tar reg.txt student@linuxmint ~ $ cd Documents student@linuxmint ~/Documents $ ls economicguru.doc laxmi.odp wwcChallenges.pdf Dr. Pauls Engineering

economicguru.odt Untitled 1.doc student@linuxmint ~/Documents $ find *.doc economicguru.doc Untitled 1.doc (v) Display the common and distinct line of contents from a file. student@linuxmint ~ $ cat > q1 name is narayan test student@linuxmint ~ $ cat >q2 name is kamal test student@linuxmint ~ $ comm -12 q1 q2 test 4. a. Write and execute the following UNIX commands (i) Create two files. student@linuxmint ~ $ cat > file1 Narayana student@linuxmint ~ $ cat > file2 Swamy (ii) Display the contents of both the files. student@linuxmint ~ $ cat file1 Narayana student@linuxmint ~ $ cat file2 Swamy (iii) Count the number of characters in both the files. student@linuxmint ~ $ wc -m file1 9 file1 student@linuxmint ~ $ wc -m file2 6 file2 (iv) Rename the two files. student@linuxmint ~ $ mv -i file1 fileone student@linuxmint ~ $ cat fileone Narayana student@linuxmint ~ $ mv -i file2 filetwo student@linuxmint ~ $ cat filetwo Swamy (v) Combine the two files without duplicate. student@linuxmint ~ $ cat filetwo >> fileone student@linuxmint ~ $ cat fileone Narayana Swamy Page 2 of 6 College

UNIX Commands 5. a. Write and execute the following UNIX commands (i) To view all the files and directories page by page student@linuxmint ~ $ ls -a | pg (ii) To view only the directories page by page. student@linuxmint ~ $ ls -d */ | pg (iii) To view only the files in a directory. student@linuxmint ~ $ ls -d *.* | pg (iv) Display the working directory. student@linuxmint ~ $ pwd /home/student (v) Display the complete path of the working directory. student@linuxmint ~ $ pwd -P /home/student 6. a. Write and execute the following UNIX commands (i) Display the calendar. student@linuxmint ~ $ cal February 2012 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 (ii) Execute more than one command at a time (using semicolon ;) student@linuxmint ~ $ date;time Mon Feb 6 22:44:08 PST 2012 real 0m0.000s user 0m0.000s sys 0m0.000s (iii) Display the users full details. student@linuxmint ~ $ who student tty7 2012-02-06 19:37 (:0) student pts/0 2012-02-06 20:15 (:0.0) (iv) Display the user-id / Group-id. student@linuxmint ~ $ id -u 1001 student@linuxmint ~ $ id -g 1001 (v) Execute more than one command at a time (using logical-AND &&). student@linuxmint ~ $ date && time Mon Feb 6 22:53:37 PST 2012 real 0m0.000s Dr. Pauls Engineering

user sys

0m0.000s 0m0.000s

7. a. Write and execute the following UNIX commands (i) Demonstrate pipe command student@linuxmint ~ $ who | wc -l 2 (ii) Demonstrate tee command student@linuxmint ~ $ who | tee sample | wc -l 2 student@linuxmint ~ $ cat sample student tty7 2012-02-06 19:37 (:0) student pts/0 2012-02-06 20:15 (:0.0) (iii) Use more than one command at a time (who and date) student@linuxmint ~ $ who;date student tty7 2012-02-06 19:37 (:0) student pts/0 2012-02-06 20:15 (:0.0) Mon Feb 6 22:55:05 PST 2012 (iv) Create a file called create.txt student@linuxmint ~ $ cat > create.txt Narayana Swamy (v) Move the file create.txt to move.txt student@linuxmint ~ $ mv create.txt move.txt student@linuxmint ~ $ cat move.txt Narayana Swamy 8. a. Write and execute the following UNIX commands (i) Create a file student@linuxmint ~ $ cat > ex1 Narayana Kamala Vimala Sudha Sooriya Hemanand (ii) Print the specified number of lines of a file from start to end of the file. student@linuxmint ~ $ head -2 ex1 Narayana Kamala (iii) Display the file content with line number student@linuxmint ~ $ nl ex1 1 Narayana 2 Kamala Page 3 of 6 College

UNIX Commands 3 Vimala 4 Sudha 5 Sooriya 6 Hemanand (iv) Update the file content with I/O redirection student@linuxmint ~ $ date > ex1 student@linuxmint ~ $ cat ex1 Mon Feb 6 23:07:27 PST 2012 (v) Rename the file student@linuxmint ~ $ mv ex1 ex2 student@linuxmint ~ $ cat ex2 Mon Feb 6 23:07:27 PST 2012 student@linuxmint ~ $ cat ex1 cat: ex1: No such file or directory 9. a. Write and execute the following UNIX commands (i) Create a directory student@linuxmint ~ $ mkdir mechanical (ii) Create a file student@linuxmint ~ $ cat > mech Majestic Mechanical (iii) Rename the directory student@linuxmint ~ $ mv mechanical civil (iv) Rename the file student@linuxmint ~ $ mv mech civ (v) View the file student@linuxmint ~ $ cat civ Majestic Mechanical 10. a. Write and execute the following UNIX commands (i) Create a file student@linuxmint ~ $ cat > home.txt My name is Narayana (ii) Update the file student@linuxmint ~ $ cat > home.txt My name is Narayana Swamy (iii) Display the file content student@linuxmint ~ $ cat home.txt My name is Narayana Swamy (iv) Display the file with line number student@linuxmint ~ $ nl home.txt 1 My name is Narayana Swamy (v) Count the number of words in the file student@linuxmint ~ $ wc -w home.txt 5 home.txt Dr. Pauls Engineering

UNIX Commands 11. a. Write and execute the following UNIX commands (i) Create a Directory called main student@linuxmint ~ $ mkdir main (ii) Create a sub-directory called sub in the main directory student@linuxmint ~ $ cd main student@linuxmint ~/main $ mkdir sub (iii) Create a file in the main directory student@linuxmint ~/main/sub $ cd /home/student/main student@linuxmint ~/main $ cat > test.txt Dr. Pauls Engineering College (iv) Copy the file to the sub directory student@linuxmint ~/main $ cp test.txt /home/student/main/sub (v) Delete the file in the main directory student@linuxmint ~/main $ rm test.txt 12. a. Write and execute the following UNIX commands (i) Display the calendar student@linuxmint ~/main/sub $ cal February 2012 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 (ii) Display the date and time student@linuxmint ~/main/sub $ date;time Mon Feb 6 23:48:43 PST 2012 real 0m0.000s user 0m0.000s sys 0m0.000s (iii) Display the present working directory student@linuxmint ~/main/sub $ pwd /home/student/main/sub (iv) Display your user name student@linuxmint ~/main/sub $ whoami student (v) Create a file using cat command student@linuxmint ~/main/sub $ cat > mech.txt We the first year mechanical guys are majestic. 13. a. Write and execute the following UNIX commands (i) Use finger command (ii) Use grep command Page 4 of 6 College student@linuxmint ~ $ cat > wow.txt Running out off words. WOW! student@linuxmint ~ $ grep 'WOW' wow.txt Running out off words. WOW! (iii) Use diff command student@linuxmint ~ $ cat > hurray.txt Running out off terms. HURRAY! student@linuxmint ~ $ diff wow.txt hurray.txt 1c1 < Running out off words. WOW! --> Running out off terms. HURRAY! (iv) Use uniq command student@linuxmint ~ $ cat > myfile.txt Narayana Kamala Sudha Sharmila Nisha Sangeetha Nisha Narayana student@linuxmint ~ $ sort myfile.txt | uniq Kamala Narayana Nisha Sangeetha Sharmila Sudha (v) Use cmp command student@linuxmint ~ $ cmp myfile.txt wow.txt myfile.txt wow.txt differ: byte 1, line 1 14. a. Write and execute the following UNIX commands (i) Create a directory student@linuxmint ~ $ mkdir directory (ii) View all directories from a user student@linuxmint ~ $ ls -d */ asd/ directory/ main/ Pictures/ Templates/ civil/ Documents/ mechanival/ prince 19.9.11/ Videos/ Desktop/ Downloads/ Music/ Public/ (iii) Rename a directory student@linuxmint ~ $ mv directory direct (iv) View all the directories starting with a specific character. Dr. Pauls Engineering

student@linuxmint ~ $ ls -d m*/ main/ mechanival/ (v) View only the hidden directories student@linuxmint ~ $ ls -a d 15. a. Write and execute the following UNIX commands (i) Create a file student@linuxmint ~ $ cat > sonali My name is Sonali Paul (ii) View only files from a directory student@linuxmint ~ $ ls *.* 1.txt 5.txt home.txt naasa.c prince 19.9.11.tar reg1.txt 2.txt cam.txt mmm.odt name1.txt prince.zip reg.txt 3.txt final.txt move.txt name.txt q.txt w.txt prince 19.9.11: 10.1.1.133.5446.pdf ranklist.pdf 1.pdf Roy.ppt ApplicationforTransactionPassword.pdf ruralnet.pdf EugenBorcociTutorial.pdf UNIT IV.ppt iapigi-081006.pdf wirelessmesh_files index_files wirelessmesh.html index.htm Wireless_Mesh_Networks.pdf mesh_network.pdf Wireless mesh networks.ppt p442-aguayo1111.pdf wwcChallenges.pdf (iii) Rename a file student@linuxmint ~ $ cat sonali paul (iv) View all files starting with a specific character student@linuxmint ~ $ ls na* naasa.c name1.txt name.txt (v) View all the files which has a specific extension student@linuxmint ~ $ ls *.txt 1.txt 3.txt cam.txt home.txt name1.txt q.txt reg.txt 2.txt 5.txt final.txt move.txt name.txt reg1.txt w.txt 16. a. Write and execute the following UNIX commands (i) Create a directory with the name of Exam student@linuxmint ~ $ mkdir Exam (ii) Change the Exam directory as the working directory student@linuxmint ~ $ cd Exam student@linuxmint ~/Exam $ (iii) Create a file called exam.txt in the Exam directory student@linuxmint ~/Exam $ cat > exam.txt I will secure more marks in examination. (iv) View the content of the exam.txt file Page 5 of 6 College

UNIX Commands student@linuxmint ~/Exam $ cat exam.txt I will secure more marks in examination. (v) Rename the file exam.txt to test.txt student@linuxmint ~/Exam $ mv exam.txt test.txt 17. a. Write and execute the following UNIX commands (i) To check the working directory student@linuxmint ~/Exam $ pwd /home/student/Exam (ii) Change the password student@linuxmint ~/Exam $ passwd Changing password for student. (current) UNIX password: Enter new UNIX password: Retype new UNIX password: Bad: new password is too simple Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully (iii) To display todays date student@linuxmint ~/Exam $ date +%d 07 (iv) To display the calendar of this month student@linuxmint ~/Exam $ cal 02 2012 February 2012 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 (v) To display a message University Exam using a special character student@linuxmint ~ $ u=U student@linuxmint ~ $ n=n student@linuxmint ~ $ i=! student@linuxmint ~ $ v=V student@linuxmint ~ $ e=E student@linuxmint ~ $ r=# student@linuxmint ~ $ s=$ student@linuxmint ~ $ i=! student@linuxmint ~ $ t=T student@linuxmint ~ $ y=Y student@linuxmint ~ $ e=E Dr. Pauls Engineering

student@linuxmint student@linuxmint student@linuxmint student@linuxmint Un!VE#$!TY E*@M

~ ~ ~ ~

$ $ $ $

x=* a=@ m=M echo $u$n$i$v$e$r$s$i$t$y $e$x$a$m

UNIX Commands student@linuxmint ~/cs1102 $ cat namesake.txt The file has been created for lab purpose. (v) Count the number of words in a file student@linuxmint ~/cs1102 $ wc -w namesake.txt 8 namesake.txt 20. a. Write and execute the following UNIX commands (i) Count the specific number of lines from a file start from the beginning of the file student@linuxmint ~ $ cat > desktop.txt Narayana Hemananda Bhagavathi Rohit Jiji Aravind student@linuxmint ~ $ head -3 desktop.txt Narayana Hemananda Bhagavathi student@linuxmint ~ $ (ii) To destroy a specific file from a user directory student@linuxmint ~ $ rm desktop.txt (iii) Send a greeting message to other user (iv) Execute a shell program student@linuxmint ~ $ cat > shell.sh echo "Enter your name" read name echo "Welcome to UNIX lab $name" student@linuxmint ~ $ sh shell.sh Enter your name Narayana Welcome to UNIX lab Narayana (v) To display current time student@linuxmint ~ $ date +%T 01:07:07 .

18. a. Write and execute the following UNIX commands (i) Create two directories called CS1101 and CS1102 student@linuxmint ~ $ mkdir cs1101 student@linuxmint ~ $ mkdir cs1102 (ii) Create a file called cs1101.txt in the CS1101 directory student@linuxmint ~ $ cat > /home/student/cs1101/cs1101.txt cs1101.txt file contents are ambiguous. (iii) Copy the file cs1101.txt from CS1101 to CS1102 student@linuxmint ~ $ cp /home/student/cs1101/cs1101.txt /home/student/cs1102 (iv) Update the file content of cs1101.txt in the CS1102 directory student@linuxmint ~ $ cd cs1102 student@linuxmint ~/cs1102 $ cat cs1101.txt cs1101.txt file contents are ambiguous. student@linuxmint ~/cs1102 $ cat > cs1101.txt The content has been updated student@linuxmint ~/cs1102 $ (v) Rename the file in the CS1102 with cs1102.txt student@linuxmint ~/cs1102 $ mv cs1101.txt cs1102.txt student@linuxmint ~/cs1102 $ cat cs1102.txt The content has been updated 19. a. Write and execute the following UNIX commands (i) Create a file student@linuxmint ~/cs1102 $ cat > summa.txt The file has been created for lab purpose. (ii) Rename a file student@linuxmint ~/cs1102 $ mv summa.txt namesake.txt student@linuxmint ~/cs1102 $ cat namesake.txt The file has been created for lab purpose. (iii) Change the mode of the file to read only student@linuxmint ~/cs1102 $ ls -l namesake.txt -rw-r--r-- 1 student student 43 2012-02-07 00:52 namesake.txt student@linuxmint ~/cs1102 $ chmod u-w namesake.txt student@linuxmint ~/cs1102 $ ls -l namesake.txt -r--r--r-- 1 student student 43 2012-02-07 00:52 namesake.txt (iv) View the content of a file Page 6 of 6 College

Dr. Pauls Engineering

Você também pode gostar