1) Explore all the UNIX commands given in this manual.
1. Date- show date and time.
2. History- list of previously executed commands.
3. Man- show on-line documentation by program name.
4. Who- who is on the system and what are they doing.
5. Who am i- who is logged onto this system.
1. Cat- combine files.
2. Cp- copy file.
3. Ls- list of file in a directory and their attributes.
4. Mv- change file name or directory location.
5. Chmod- set file permission.
Display contents of files:-
1. Cat- copy file to display device.
2. Vi- Screen editor for modify text files.
3. More- show text files on display terminal with paging control.
4. Head- show first few lines of a file.
5. Tail- show last few lines of file or reverse line order.
6. Grep- display lines that match a pattern.
1. Cd- change to new directory.
2. Mkdir- create new directory.
3. Rmdir-remove empty directory.
4. Mv- change name or directory location.
5. Pwd- show present working directory.
2) Create a directory.
For ex:- mkdir abc
3) Create a subdirectory in the directory created.
Answer- step-1: first create a directory
For ex:- mkdir rootdirectory
Step-2: then enter in rootdirectory
For ex: cd rootdirectory
Step-3: then create another directory
For ex: mkdir subdirectory.
4) Change your current directory to the subdirectory.
5) Display the calendar for the current month.
For ex: cal 2010
6) Get a directory listing of the parent directory.
7) How many users were logged onto your system?
8) Display your name in the form of a banner.
Answer -Banner Abhi
9) Display the name of device name of your terminal.
10) Move to the root directory.
11) Change your directory to the directory exercises. Create a file called example1 using the cat command containing the following text:
water, water everywhere
and all the boards did shrink;
water, water everywhere,
No drop to drink.
Answer -Mv mydirectory exercise
Step-1: cat example
Step-2: type the text
Step-3: Press ctrl+D for save
12) Use the man command to obtain further information on the finger command.
Answer -Man finger
13) List all the processes that are presently running.
14) List the text files in your current directory.
Answer -Find/ usr –type –name *.txt print
15) Make a copy of any text file.
16) Rename one of your text files in the current directory.
17) Delete an unneeded copy of a file.
18) Print out any file on paper.
19) Send a message to another user on your UNIX system, and get them to reply.
Answer -Write user
20) Create a small text file and send it to another user.
21) When you receive a message, save it to a file other than your mailbox.
Answer -We can open all received message by
Then we save a mail message to a file by
22) Send a message to a user on a different computer system.
Answer -Mail mca11 ttyp5
How are you?
Then press ctrl+D .
23) Try to move to the home directory of someone else in your group. There are several ways to do this, and you may find that you are not permitted to enter certain directories. See what files they have, and what the file permissions are.
Answer -Cd user/mca11
24) Try to copy a file from another user’s directory to your own.
$ cp xyz.txt/user2/mca12
25) Set permissions on all of your files and directories to those that you want. You may want to give read permission on some of your files and directories to members of your group.
Answer -$chmod –R 777 abc.txt
26) Create a number of hierarchically related directories and navigate through them using a combination of absolute pathnames (starting with "/") and relative pathnames.
27) Try using wildcards (“*” and possibly “?”).
Answer -$ls *.txt
This command will display the listing of all files having extension .txt.
28) Put a listing of the files in your directory into a file called filelist. (Then delete it!)
Answer -$ls *.txt
$find filename.txt –printr> filename.txt
$rm file list
29) Create a text file containing a short story, and then use the spell program to check the spelling of the words in the file.
Type the text
Press ctrl+D to save.
30) Redirect the output of the spell program to a file called errors.
Answer -$spell story.txt>error
31) Type the command ls -l and examine the format of the output. Pipe the output of the command ls -l to the word count program wc to obtain a count of the number of files in your directory.
Answer -$ls –l |wc -c
32) Use cut to strip away the reference material and leave just the text field.
Answer -$cat –F 1-3-d
33) Use tr to strip away any tags that are actually in the text (e.g., attached to the words), so that you are left with just the words.
Answer -$tr –d –c setting1.
34) Set a file to be read-only with the chmod (from change mode) command. Interpret the file permissions displayed by the ls -l command.
Answer -$chmod 444
35) Delete one or more directories with the rmdir (from remove directory) command. See what happens if the directory is not empty. Experiment (carefully!) with the rm -r command to delete a directory and its content.
$rm –r abc
36) Experiment with redirecting command output (e.g., ls -l >file1). Try ">> " instead of " >" with an existing text file as the output.
Answer -$ls –l>> file
This will append the text in existing file.
37) See whether upper-case versions of any of these commands work as well as the lower-case versions.
Answer -$ls –l>file name
38) Use the who command to see users logged into the system.
Mca1 ttyp7 mar20 15:14
Mca2 ttyp5 mar19 11:11
Mca2 ttyp6 mar16 11:10
Mca3 ttyp7 mar11 13:11
39) Pipe the output of the who command to the sort command
Answer -$who|sort -4
40) Search for your login name in whofile using the grep command.
Answer -$who >who file
$grep mca22 whofile
$who |grep mca22
41) Compare two text files with the diff command.
Answer -$diff file1 file2
42) Count lines, words, and characters in a file with the wc command.
Answer -$wc –c for characters
$wc –l for lines
$wc –w for wordss
43) Display your current environment variables with the following command: set or env.
Answer -$set or $env both are same
$set or $env
LOG NAME= mca22
44) Concatenate all files in a directory redirected to /dev/null and redirecting standard error to “errorFile”?
Answer -$cat *>>file name
Cat: input error: is a directory
Dr wxh –xh –x2bca22 9-bca siz Dec 30 12:50
$cat file name
45) Display information on yourself or another user with the finger command.
Login name tty idle login time Where
Mca1 *P20 15:49 22:11 192.168.22.3
Mca2 *P21 12:22 21:11 192.168.2.3
Mca3 *P23 14:49 12:11 192.168.2.5
Mca4 *P26 11:49 22:11 192.168.2.2
47) Delete all the files in the current directory whose name ends in “.bak”.
$ls –l *.back
48) Display lines 10 to 14 of any file which contains 25 lines.
Answer -$tail +10 file name|head -5
$head -10 file1| tail -14 file
49) Count how many lines contain the word science in a word file science.txt.
Answer -Cat> science.txt
- - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - science- - - - - -
predd ctrl+D to save
$grep –c “science” science.txt |wc -l
50) List the statistics of the largest file (and only the largest file) in the current directory.
Answer -$ls –l| grep ‘n’ |sort>m1
$cat –d –f 4|sort m1;tail -l
51) Kill any process with the help of the PID and run any process at the background.
52) Select a text file and double space the lines.
Abc efg hig
Ctrl+d to save.
$ps -d>plog1.txt [second file]
Abc efg hig
53) List all the users from /etc/passwd in the alphabetically sorted order.
Answer -$cat /etc/password|sort
54) Create a file with duplicate records and delete duplicate records for that file.
Answer -$cat b11.txt
Abhishek abhishek abhishek
Ctrl+D to save.
$uniq –c b11.txt
$Cp ab.txt abc.txt
55) Use the grep command to search the file example1 for occurrences of the string “water”.
For I in cat example1
$cat ex1|grep –c “water”
$grep water example1
56) Write grep commands to do the following activities:
• To select the lines from a file that have exactly two characters.
$grep ‘^.$’ n1
• To select the lines from a file that start with the upper case letter.
$grep ‘[A-Z] ^1
• To select the lines from a file that end with a period.
• To select the lines in a file that has one or more blank spaces.
$grep ‘ ‘n1
• To select the lines in a file and direct them to another file which has digits
as one of the characters in that line.
$grep ‘[0-9]’ n1>n2
57) Make a sorted wordlist from the file.
Answer -$tr ‘A-Z’ ‘a-z’ < file1|tr –cs ‘a-z’ ‘\02’|sort |uniq –c>file2
58) Try to execute the example shell scripts given in this manual.
Answer -$vi nv
Echo “Enter any no.”
Echo “Number is 4a”
59) Write a shell script that searches for a single word pattern recursively in the current directory and displays the no. of times it occurred.
Answer -$grep –r ‘ABC’
61) Write a shell script that accepts a string from the terminal and echo a suitable message if it doesn’t have at least 5 characters including the other symbols.
Echo “Enter the string”
C=`expr $s |wc –c`
C=`expr $c -1`
If Test $c –ge 5
Echo “String is valid”
Echo “String is invalid”
62) Write a shell script to echo the string length of the given string as argument.
Echo “enter the String”
C=’echo $a |wc –c’
C=`expr $c -1`
63) Write a shell script that accepts two directory names as arguments and deletes those files in the first directory which are similarly named in the second directly. Note: Contents should also match inside the files.
Echo “enter the fist Dir”
Echo “Enter the second Dir”
Ls $a >> aa
Ls $b >> bb
For ‘in comm. -1-2 aabb’
If Test $q –eq 0
64) Write a shell script to display the processes running on the system for every 30 seconds, but only for 3 times.
While Test $i –le 3
Do sleep 5
i=`expr $i +1`
65) Write a shell script that displays the last modification time of any file.
Ls –l put|cat –c -45 -48
66) Write a shell script to check the spellings of any text document given as an argument.
Echo “enter the file”
Spell $a> error
69) Write a shell script which reads the contents in a text file and removes all the blank spaces in them and redirects the output to a file.
W=`wc –w Test`
Echo “No of word $w”
Set ‘cat jay’
While test $c –le $w
Echo –n $i>>jay
C=`expr $c +1`
For I in ‘cat jay’
Echo –n 4i
70) Write a shell script that changes the name of the files passed as arguments to lowercase.
Tr “[:uppr:]” “[:lowe:]” [temp]
71) Write a shell script to translate all the characters to lower case in a given text file.
Echo enter a text file
If [1 $file]
Echo 4file not a file
Cat $file |tr ‘[A-Z]’ ‘[a-z]’
72) Write a shell script to combine any three text files into a single file (append them in the order as they appear in the arguments) and display the word count.
File3=$3 out- ‘output $1’
If [$# -ne 3]
Echo “$(base name $o) file1 file 2file3”
Echo ‘$file! Not a file’
If[! –f $file2]
Echo “$file2 not file!”
If [1- f $file]
Echo $file3 not a file!”
$file1 $file 2$file3?? $out
Count=4(cat $out|wc –w)
Echo “count words written to out!”
28 October, 2010