UNIX Lab Manual
LAB1
1. Display man page of cal
2. How to show a calendar in the terminal
3. How to output more than one month
4. How to display the day of the year in numbers
5. How to print a calendar for a particular day, month and year
6. Explain cal 9 1752
7. Display man page of date
8. Displays the current date and time
9. Display only the present month
10. Display the month name
11. Display the present month and month name
12. Display the date in mm/dd/yy format
13. Display only current hour
14. Display only current minute
15. Display only current second
16. Display the last two digits of the year
17. Display man page of echo
18. Display Hello world
19. Use bc calculator to do the followings:
a. 12+5
b. 12*5
c. 12^2
d. 9/5
e. 17/7 (using scale is equal to 2)
LAB 2
20. Convert binary to decimal using bc
21. Convert decimal to binary
22. Display man page of who
23. Find out who has logged in
24. Display boot time of last system boot
25. Display who command with heading
26. Display current run level
27. Display man page of uname
28. Display your machine’s characteristics
29. Display the name of the platform
30. Display the machine’s hardware name
31. Display man page of tty
32. Display the device name of your terminal
33. What is the output of echo $HOME
1
UNIX Lab Manual
LAB 3
34. Display the pathname to the current directory
35. Create the following file structure under your home directory
LAB 4
36. Create the following ordinary files in BCA5A or BCA5B (depending upon your section)
a. dept.lst
01:accounts:6213
02: admin:5423
b. emp.lst
0001|Dipankar Das |teacher|THA
0002|Parichay Chakraborty |teacher|THA
0003|Arnab Kole |teacher|THA
0004|Joydeep Das |teacher|THA
0005|Bratin Maity |teacher|THA
0006|Somnath Bhattacharya |teacher|THA
c. addressbook
dd
dd@test.com
1111100001
pc
pc@test.com
1111100002
2
UNIX Lab Manual
d. file1
5
2
10
1
37. Navigate to BCA1A from your home directory. Practice both
a. Absolute pathname
b. Relative pathname
38. Go to your home from BCA1A
39. Navigate to BCA1A from your home directory. From that directory navigate to BCA5A or BCA5B
(depending upon your section). Practice both
a. Absolute pathname
b. Relative pathname
40. Create a directory test under BCA1A. Create an ordinary file text under it. Now remove the
directory test.
LAB 5
41. Navigate to BBA1A from BCA1A using .. (dot dot)
42. Show an example of the use of . (dot)
43. List file’s type and inode number
44. List a particular directory’s content
45. Display the content of THA in recursive manner
46. Display the hidden file
47. Display the name of the current directory
48. Long list the directory THA and explain the output
49. Display the content of dept.lst
50. Display the content of dept.lst and emp.lst
51. Create a directory BCA5_Backup under BCA5A or BCA5B (depending upon your section).
LAB 6
52. Copy all the ordinary files from BCA5A or BCA5B into BCA5_Backup
53. Create a file chap1 and a directory progs under your home directory. Explain what happens:
a. cp chap1 progs/unit1
b. cp chap1 progs
54. Create two files chap2 and chap3 under your home directory. Copy chap1, chap2 and chap3 into
BCA5A or BCA5B (depending upon your section) using a single command.
55. What happens if you give the command cp –R progs newprogs from your home directory:
a. If newprogs does not exists
b. if newprogs exists
56. Delete chap1, chap2 and chap3 from BCA5A or BCA5B (depending upon your section)
3
UNIX Lab Manual
LAB 7
57. Rename chap1, chap2 and chap3 to man1, man2 and man3 in your home directory
58. What happens if we execute the following command:
a. mv chap1 chap2 chap3 progs
b. mv progs newprogs1
59. What happens if you give the command mv progs newprogs1 (After question 58)
60. Display the file type of chap1
61. Display the number of lines, words and characters of file dept.lst
62. Display the number of lines, words and characters of file dept.lst separately
63. Create two files File1 and File2 under your home directory, the contents are given below
64. Display the location of the first mismatch in the two files (File1 and File2)
65. Display a detailed list of mismatches in the two files (File1 and File2)
LAB 8
66. Display the lines unique to the first file (File1)
67. Display the lines unique to the second file (File2)
68. Display the lines lines common to both the files (File1 and File2)
69. Create two files email and addresses
70. Display the file differences of both the files (email and addresses). Explain the output.
71. Create a directory Wildcards under BCA5A or BCA5B (depending upon your section). Create
ordinary files Chap, Chap01, Chap02, Chapx, Chapy, Chapz, emp.lst, emp1.lst, emp22lst, a.c, a.o,
1.c inside it.
4
UNIX Lab Manual
LAB 9
72. List all the files whose name start with Chap
73. List all the files whose name start with Chap and after that have only one character
74. List all the files whose name start with Chap and after that have any two characters
75. What will the output of ls emp*lst
76. What will be the output of
a. ls Chap0[124]
b. ls Chap0[1-4]
c. ls Chap[x-z]
77. List all the files with an extention either .c or .o
78. List all the files with an extention neither .c nor .o
79. List all the files with a single character extention but not .o
80. List all the files beginning with a small letter (alphabet)
81. List all the files beginning with a capital letter (alphabet)
82. List all the files not beginning with an alphabet
LAB 10
83. Create a file Chap*, Chap0[1-3], My Documents.doc under BCA5A or BCA5B (depending upon
your section).
84. List the file Chap* (use escaping & quote both)
85. List the file Chap0[1-3] (use escaping & quote both)
86. List the file My Documents.doc (use escaping & quote both)
87. Show an example to illustrate the use of single quote and double quote
88. Count the number of users who has logged in by creating a new file
89. Count the number of users who has logged in without creating a new file
90. Count the number of users who has logged in and store the output in a file (don’t display the
output on terminal)
91. Count the number of users who has logged in and display the output on terminal and store the
output in a file
92. Count the number of files in your home directory (say n number of files) and display it with user
defined message e.g. There are n number of files in the current directory
93. Assign a value 17 in a shell variable named x and display its content
94. Remove the shell variable x
5
UNIX Lab Manual
95. Create a file emp_test.txt in your home directory. The file is having three fields (id, name and
city) separated by “|” symbol as given below:
0 1 | A A | K O L
0 2 | B | K O L
0 3 | C C C | K O L
0 4 | D | K O L
0 5 | E E E | K O L
0 6 | F F | K O L
0 7 | G | K O L
0 8 | H H | K O L
0 9 | I I I | D E L
1 0 | J | M U M
1 1 | K K | M U M
1 2 | M M | M U M
96. Print the file emp_test.txt using pr command and briefly explain the output
LAB 11
97. Print the file emp_test.txt by
a. Suppressing headers and footers
b. Double space input
c. With line numbers
d. Offset the lines by 10 spaces
98. Display first 10 lines of the file emp_test.txt
99. Display first 3 lines of the file emp_test.txt
100. Display the last 10 lines of the file emp_test.txt
101. Display the last 3 lines of the file emp_test.txt
102. Display the file emp_test.txt from 11th line onwards
103. Display only the names from emp_test.txt
104. Display id and city from emp_test.txt
105. Display name and city from emp_test.txt
LAB 12
106. Create another file emp_test1.txt from emp_test.txt with the order of the fields will be
name, city and id
(Hint:
In emp_test.txt -> id, name, city
In emp_test1.txt -> name, city, id)
107. Display the content of the file addressbook
108. Display the content of the file addressbook in a single line i.e. join the lines of the file
109. Create a file addressbook1 in the following format:
6
UNIX Lab Manual
d d|dd@test.com|1111100001
p c|pc@test.com|1111100002
110. Sort the file emp.lst on the second field
111. Sort the file emp.lst on the second field in reverse order
112. Create a file file_numeric in your home directory, the content of which is as follows:
10
2
4
27
113. What is the output of sort file_numeric? Explain.
LAB 13
114. Perform numeric sort of the file file_numeric file.
115. Create a file file_emp in your home directory, the content of which is as follows:
A
A
B
C
D
A
116. Remove the repeating lines from the output
117. Sort the file file_emp and store the output in another file called file_emp1
118. Check whether the file file_emp1 is sorted or not
LAB 14
119. Create a file named file_emp2 in your home directory, the content of which is as
follows:
Das
Das
Chakrabarti
Chakraborty
Maiti
Mitra
120. Display the uniq occurrence of the names
121. Display non repeated lines
122. Display only one copy of the repeated lines
123. Display the frequency of occurrence of all lines
7
UNIX Lab Manual
124. Create a file in your home directory file_emp3, the content of which is as follows:
DIPANKAR DAS |TEACHER|THA
PARICHAY CHAKRABARTI|TEACHER|THA
AWANIS TIWARI |ADMIN |THA
125. Replace the | symbol with ~ (file: file_emp3)
LAB 15
126. Change all the uppercase to lowercase (file: file_emp3)
127. Delete the character | (file: file_emp3)
128. Compress multiple consecutive characters and display (file: file_emp3)
129. Display the content of the file file_emp3 in the following way:
DIPANKAR DAS
|
TEACHER
|
THA
…..
130. Search the pattern TEACHER in the file file_emp3
131. Search the pattern DIPANKAR DAS in the file file_emp3
132. Display all the lines except the lines containing TEACHER in the file file_emp3
133. Append the file file_emp3 with the following entry:
Dipankar DAS |TEACHER|THA
LAB 16
134. Search for the pattern DIPANKAR DAS from the file file_emp3 ignoring the case
135. Count how many teachers and how many admin staff is there in the file file_emp3
136. Create a file file_emp4 in your home directory, the content is as follows:
Agarwal
aggarwal
agrawal
137. Search the patterns Agarwal, aggarwal and agrawal using a single command from file
file_emp4
138. Write the patterns to be searched (Agarwal, aggarwal and agrawal) in a file pattern.lst
and search the file file_emp4 taking the input from it
139. Use BRE to search the patterns Agarwal, aggarwal and agrawal from file file_emp4
8
UNIX Lab Manual
LAB 17
140. Write a shell script to print “Knowledge is power”
141. Write a shell script to print
a. Who currently logged in
b. Current date and time
c. Number of users logged in
LAB 18
142. Write a shell script to
a. Define variable x with value 10 and print it
b. Define variable xn with value THA and print it
c. Print sum of two numbers say 6 and 3
d. Define two variable x1=20, x2=5 and then to print division of x1 and x2
e. Store division of x1 and x2 to variable called z and print z
143. Script to read your name from key-board
144. Script to read two numbers from keyboard and print their
a. Addition
b. Subtraction
c. Multiplication
d. Division
e. Reminder
LAB 19
145. Script to show all files whose first name is starting with letter 'a'
146. Script to show all files having extension .sh
147. Script to show all files having extension .sh but file name must start with 'f'
148. Script to show all files whose names are 1 character long
149. Script to show all files whose names are 3 character long
150. Script to show all files whose names are 5 character long and file name begin with
'fi'
LAB 20
151. Script to show all files whose names are beginning with letters a,b,c
152. Script to print sorted list of users
153. Script to write sorted list of users into user_list file
154. Script to print number of users
155. Script to print number of files in current directory
156. Script to see if a particular user is logon or not
157. Script to take input from a file which has names of different persons and store the
unique names in a file called u_sname
9
UNIX Lab Manual
LAB 21
158. Script to print a file where the file name will be supplied as command line argument
159. Script to see whether argument is positive
160. Script to see whether argument is positive or negative
161. Script to show an application of nested if
162. Script to test if..elif...else
163. Script to test for loop
164. Script to print multiplication table
165. Script to test while statement
166. Shell script to calculates the gross salary. (HRA = 20% of basic salary, DA = 50% of
basic salary)
LAB 22
167. Shell Script to Generate Fibonacci Series
168. Shell script to find the sum of digits of a number
169. Shell script, which receives two filenames as arguments.
a. It checks whether the two files contents are same or not.
b. If they are same then second file is deleted.
170. Menu driven Shell script that
a. Lists current directory,
b. Prints Working Directory
c. displays Date
d. displays Users logged in
171. Shell script for a simple calculator
172. Shell program to generate all combinations of 1, 2, and 3
173. Shell script which whenever gets executed displays the message “Good
Morning/Good afternoon /Good Evening“ depending on the time it get executed
174. Write a shell script to reverse the content of a file
175. Shell script to check whether the given number is prime or not.
176. Shell Script to Find Armstrong Numbers between a Range
177. Shell Script to find profit or loss given the Cost price and Selling price
178. Decimal to Binary Conversion Shell Script
LAB 23
179. Write a script to make Following File and Directory Management Operations menu
based
a. Display Current dirctory
b. List Directory
c. Make Directory
d. Change Directory
e. Copy A File
10
UNIX Lab Manual
f. Rename A File
g. Delete A File
h. Edit a file
180. Write a shell script to count length of user input string
181. Write a shell program to add, subtract and multiply the 2 given numbers passed as
command line arguments.
182. Write a shell program to exchange the value of two variables.
183. Write a shell script to print command line argument like $#, $0, $1, $*, $@
184. Write a shell script to print a number is positive or negative or null.
185. Write a shell script, which displays a list of all files in the current directory to which you
have read, write and execute permissions.
LAB 24
186. Write a shell script to count vowels, blank spaces, characters, number of line and
symbols.
187. Write a shell script to find the sum, the average and the product of the four integers
entered
188. Write a script to delete zero sized files from a given directory (and all its subdirectories)
189. Write a program to calculate the factorial of a number.
190. Write a shell program to display the alternate digits in a given 7 digit number starting
from the first digit.
191. Write a script to print all prime numbers from 1 to 300.
192. Write a shell program to find the gcd for the 2 given numbers
193. Write a Shell Script for generating a mark sheet.
LAB 25
194. Write a shell script to sort the given numbers in descending order using Bubble sort
195. Write a shell program to find the sum of the series sum=1+1/2+...+1/n
196. Write a Shell Script to read data from a file.
197. Write a shell script to convert a file to lower case or upper case as specified by user.
198. Write a shell script to perform operations like compare strings, concatenate strings, find
length of a string, occurrence of word in a string and reverse a string
199. Script to check given string is palindrome or not.
200. Show the pattern using for loop
1
22
333
4444
55555
TAKE BACKUP OF ALL FILES IN YOUR EXTERNAL DRIVE AND SUBMIT WITHIN THE DUE DATE PROVIDED
BY THE LAB INSTRACTOR
11