0% found this document useful (0 votes)
5 views39 pages

Assignment 2

Unix assignment

Uploaded by

Ayushi Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views39 pages

Assignment 2

Unix assignment

Uploaded by

Ayushi Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

LAB-1

1. Display man page of cal.


Ans.

2. How to show a calender in the terminal.


Ans.

3. How to output more than one month.


Ans.

4. How to dispaly the day of the year in number?


Ans.
5. How to print a calender for a particular day, month and year?
Ans.

6. Explain cal 9 1752.


Ans. In September 1752, the calender transitoned from Julian calender to Greogorian calender
which resulted in a calender adjustment, as 11 days were omitted. The transition directly affected
the dates September 3 to September 13, 1752. Therefore, the command $cal 9 1752 will show the
dates like 1,2,14,15...

7. Display man page of date.


Ans.

8. Display the current date and time.


Ans.

9. Display only the present month.


Ans.

10. Display the month name.


Ans.

11. Display the present month and month name.


Ans.
12. Display the date in mm//dd//yy format.
Ans.

13. Display only current hour.


Ans.

14. Display only current minute.


Ans.

15. Display only current second.


Ans.

16. Display the last two digits of the year.


Ans.

17. Display man page of echo.


Ans.

18. Display Hello World.


Ans.
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)
Ans.

LAB-2

20. Convert binary to decimal using bc.


Ans.

21.Convert decimal to binary.


Ans.

22. Display man page of who.


Ans.
23. Find out who has logged in.
Ans.

24. Display boot time of last system boot.


Ans.

25. Display who command with heading.


Ans.

26. Display current run level.


Ans.

27. Display man page of uname.


Ans.
28. Display your machine’s characteristics.
Ans.

29. Display the name of the platform.


Ans.

30. Display the machine’s hardware name.


Ans.

31. Display man page of tty.


Ans.

32. Display the device name of your terminal.


Ans.

33. What is the output of echo $HOME.


Ans.
LAB-3

34. Display the pathname to the current directory.


Ans.

35.
Ans.

LAB-4

36. Create ordinary files in BCA5A.


Ans.

37. Navigate to BCA1A from your home directory.Practice both:


a) absolute pathname
b)relative pathname
Ans. a)

b)
38. Go to your home from BCA1A.
Ans.

39. Navigate to BCA1A from your home directory. From that directory navigate to BCA5A.
Practice both.
a) Absolute Pathname
b) Relative Pathname
Ans.
a)

b)

40. Create a directory test under BCA1A. Create an ordinary file text under it. Now remove the
directory test.
Ans.
LAB-5

41. Navigate to BBA1A from BCA1A using ..(dot dot).


Ans.

42. Show an example of the use of .(dot).


Ans.

43. List file’s type and inode number.


Ans.

44. List a particular directory’s content.


Ans.

45. Display the content of THA in recursive manner.


Ans.
46. Display the hidden file.
Ans.

47. Display the name of the current directory.


Ans.

48. Long list the directory THA and explain the output.
Ans.

This will provide the detailed list, showing information such as file permissions,number of
links, owner, group, file size, modification time and the file or directory name.

49. Display the content of dept.lst.


Ans.

50. Display the content of dept.lst and emp.lst.


Ans.

51. Create a directory BCA5_Backup under BCA5A.


Ans.
LAB-6
52. Copy all ordinary files BCA5A into BCA5_Backup.
Ans.

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
Ans.

a) The content of the chap1 file will be copied into the file namely until which is in the progs
directory.
b) The chap1 will be copied in the progs directory with the same filename.

54. Create two files chap2 and chap3 under your home directory. Copy chap1,chap2 and chap3 into
BCA5A using a single command.
Ans.

55. What happens if you give the command cp -R progs newprogs from your home directory:
a) if newprogs does not exist.
b) if newprogs exists.
Ans.

a) It will automatically create the newprogs directory and copy all the files of progs directory
recursively.
b) It will copy all the files of progs directory into the newprogs directory recursively.

56. Delete chap1,chap2 and chap3 from BCA5A.


Ans.
LAB-7

57. Rename chap1,chap2 and chap3 to man1,man2 and man3 in your home directory.
Ans.

58. What happens if we execute the following command:


a) mv chap1 chap2 chap3 progs
b) mv progs newprogs1
Ans.
a)

b)

59. What happens if you give the command mv progs newprogs1(After question 58).
Ans.

60. Display the file type of chap1.


Ans.

61. Display the number of lines,words and characters of file dept.lst.


Ans.
62. Display the number of lines,words and characters of file dept.lst separately.
Ans.

63. Create two files File1 and File2 under your home directory, the contents are given below:
Ans.

64. Display the location of the first mismatch in the two files (File1 and File2).
Ans.

65. Display a detailed list of mismatches in the two files (File1 and File2).
Ans.

LAB-8

66. Display the lines unique to the first line.


Ans.

67. Display the lines unique to the second file.


Ans.
68. Display the lines common to both the files.
Ans.

69. Create two files email and addresses.


Ans.

70. Display the file differences of both the files. Explain the output.
Ans.

71. Create a directory Wildcards under BCA5A.Create ordinary files inside it.
Ans.

LAB-9
72. List all the files whose name start with Chap.
Ans.

73. List all the files whose name start with Chap and after that have only one character.
Ans.

74. List all the files whose name start with Chap and after that have any two characters.
Ans.
75. What will be the output of ls emp*lst?
Ans.

76. What will be the output of:


a. ls Chap0[124]
b. ls Chap0[1-4]
c. ls Chap[x-z]
Ans.
a.

b.

c.

77. List all the files with an extension either .c or .o


Ans.

78. List all the files with an extension neither .c nor .o.
Ans.

79. List all files with a single character extension but not .o.
Ans.

80. List all files beginning with a small character.


Ans.

81. List all files beginning with a capital letter.


Ans.
82. List all the files not beginning with an alphaber.
Ans.

LAB-10
83. Create a file Chap*,Chap0[1-3], My Document.doc under BCA5A.
Ans.

84. List the file Chap*. (using escaping and quote both).
Ans.

85. List the file Chap0[1-3]. (using escaping and quote both).
Ans.

86. List the file MyDocuments.doc. (using escaping and quote both).
Ans.

87. Show an example to illustrate the use of single quote and double quote.
Ans.

88. Count the number of users who has logged in by creating a new file.
Ans.

89. Count the number of users who has logged in without creating a new file.
Ans.
90. Count the number of users who has logged in and store the output in a file.(don’t display the
output on the terminal)
Ans.

91. Count the number of users who has logged in and display the output on the terminal and store
the output in a file.
Ans.

92. Count the number of files in your home directory and display it with user defined message.
Ans.

93. Assign a value 17 in a shell variable named x and display its contents.
Ans.

94. Remove the shell variable x.


Ans.

95. Create a file emp_test.txt in your home directoy.


0 1 | AA | K O L
02|B |KOL
0 3 | C C C| K O L
04|D |KOL
0 5 | E E E| K O L
0 6 | F F| K O L
07|G |KOL
08|HH |KOL
0 9 | I I I| D E L
10|J |MUM
11|KK |MUM
12|MM |MUM
Ans.
96. Print the file emp_test.txt using pr command and briefly explain the output.
Ans.

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.
Ans.
a)

b)
c)

d)

98. Display first 10 lines of the file emp_test.txt.


Ans.

99. Display first 3 lines of the file emp_test.txt.


Ans.

100. Display last 10 lines of the file emp_test.txt.


Ans.

101. Display last 3 lines of the file emp_test.txt.


Ans.

102. Display the file emp_test.txt from 11th line onwards.


Ans.

103. Display only the names form emp_test.txt.


Ans.

104. Display id and city fromemp_test.txt.


Ans.

105. Display name and city from emp_test.txt.


Ans.

LAB-12

106. Display the content of the file addressbook.


Ans.

107
.
Display the content of the addressbook in a single line i.e. join the lines of the file.
Ans.

108. Create a file addressbook1 in the following format:


dd|[email protected]|1111100001
pc|[email protected]|1111100002
Ans.

109. Sort the file emp.lst on the second field.


Ans.

110. Sort the file emp.lst on the second field in reverse order.
Ans.

111. Create a file file_numeric in your home directory, the content of which is as follows:
10
2
4
27
Ans.

112. What is the output of the sort file_numeric ? Explain.


Ans.

LAB-13
113. Perform numeric sort of the file file_numeric file.
Ans.
114. Create a file file_emp in your home directory, the content of which is as follows:
A
A
B
C
D
A
Ans.

115. Remove the repeating lines from the output.


Ans.

116. Sort the file file_emp and store the output in another file called file_emp1.
Ans.

117. Check whether the file file_emp1 is sorted or not.


Ans.

LAB-14
118. Create a file named file_emp2 in your home directory, the content of which is as follows:
Das
Das
Chakrabarti
Chakraborty
Maiti
Mitra
Ans.
119. Display the uniq occurrence of the names.
Ans.

120. Display non repeated lines.


Ans.

121. Display only one copy of the repeated lines.


Ans.

122. Display the frequency of occurrence of all lines.


Ans.

123. 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
Ans.

124. Replace the | symbol with ~ (file: file_emp3).


Ans.

LAB-15

125. Change all the uppercase to lowercase (file: file_emp3).


Ans.
126. Delete the character | (file: file_emp3).
Ans.

127. Compress multiple consecutive characters and display (file: file_emp3).


Ans.

128. Display the content of the file file_emp3 in the following way:
DIPANKAR DAS
|
TEACHER
|
THA
…..
Ans.

129. Search the pattern TEACHER in the file file_emp3.


Ans.

130. Search the pattern DIPANKAR DAS in the file file_emp3.


Ans.

131. Display all the lines except the lines containing TEACHER in the file file_emp3.
Ans.

132. Append the file file_emp3 with the following entry:


Dipankar DAS |TEACHER|THA
Ans.
LAB-16
133. Search for the pattern DIPANKAR DAS from the file file_emp3 ignoring the case.
Ans.

134. Count how many teachers and how many admin staff is there in the file file_emp3.
Ans.

135. Create a file file_emp4 in your home directory, the content is as follows:
Agarwal
aggarwal
agrawal
Ans.

136. Search the patterns Agarwal, aggarwal and agrawal using a single command from file
file_emp4.
Ans.

137. 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.
Ans.

138. Use BRE to search the patterns Agarwal, aggarwal and agrawal from file file_emp4.
Ans.

LAB-17
139. Write a shell script to print “Knowledge is power”.
Ans.
140. Write a shell script to print
a. Who currently logged in
b. Current date and time
c. Number of users logged in
Ans.

LAB-18
141. 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
Ans.

142. Script to read your name from key-board.


Ans.

143. Script to read two numbers from keyboard and print their
a. Addition
b. Subtraction
c. Multiplication
d. Division
e. Reminder
Ans.

LAB-19
144. Script to show all files whose first name is starting with letter 'a'.
Ans.
145. Script to show all files having extension .sh.
Ans.

146. Script to show all files having extension .sh but file name must start with 'f'.
Ans.

147. Script to show all files whose names are 1 character long.
Ans.

148. Script to show all files whose names are 3 character long.
Ans.

149. Script to show all files whose names are 5 character long and file name begin with 'fi'.
Ans.

LAB-20
150. Script to show all files whose names are beginning with letters a,b,c.
Ans.

151. Script to print sorted list of users.


Ans.
152. Script to write sorted list of users into user_list file.
Ans.

153. Script to print number of users.


Ans.

154. Script to print number of files in current directory.


Ans.

155. Script to see if a particular user is logon or not.


Ans.

156. Script to take input from a file which has names of different persons and store the unique
names in a file called u_sname.
Ans.

LAB-21
157. Script to print a file where the file name will be supplied as command line argument.
Ans.

158. Script to see whether argument is positive.


Ans.
159. Script to see whether argument is positive or negative.
Ans.

160. Script to show an application of nested if.


Ans.

161. Script to test if..elif...else.


Ans.

162. Script to test for loop.


Ans.

163. Script to print multiplication table.


Ans.
164. Script to test while statement.
Ans.

165. Shell script to calculates the gross salary. (HRA = 20% of basic salary, DA = 50% of basic
salary).
Ans.

LAB-22
166. Shell Script to Generate Fibonacci Series.
Ans.

167. Shell script to find the sum of digits of a number.


Ans.

168. 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.
Ans.
169. Menu driven Shell script that
a. Lists current directory,
b. Prints Working Directory
c. displays Date
d. displays Users logged in
Ans.

170. Shell script for a simple calculator.


Ans.
171. Shell program to generate all combinations of 1, 2, and 3.
Ans.

172. Shell script which whenever gets executed displays the message “Good Morning/Good
afternoon /Good Evening“ depending on the time it get executed.
Ans.

173. Write a shell script to reverse the content of a file.


Ans.

174. Shell script to check whether the given number is prime or not.
Ans.
175. Shell Script to Find Armstrong Numbers between a Range.
Ans.

176. Shell Script to find profit or loss given the Cost price and Selling price.
Ans.

177. Decimal to Binary Conversion Shell Script.


Ans.

LAB-23
178. 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
f. Rename A File
g. Delete A File
h. Edit a file
Ans.

179. Write a shell script to count length of user input string.


Ans.

180. Write a shell program to add, subtract and multiply the 2 given numbers passed as command
line arguments.
Ans.

181. Write a shell program to exchange the value of two variables.


Ans.

182. Write a shell script to print command line argument like $#, $0, $1, $*, $@ .
Ans.
183. Write a shell script to print a number is positive or negative or null.
Ans.

184. Write a shell script, which displays a list of all files in the current directory to which you have
read, write and execute permissions.
Ans.

LAB-24
185. Write a shell script to count vowels, blank spaces, characters, number of line and symbols.
Ans.
186. Write a shell script to find the sum, the average and the product of the four integers entered.
Ans.

187. Write a script to delete zero sized files from a given directory (and all its subdirectories).
Ans.

188. Write a program to calculate the factorial of a number.


Ans.

189. Write a shell program to display the alternate digits in a given 7 digit number starting from the
first digit.
Ans.
190. Write a script to print all prime numbers from 1 to 300.
Ans.

191. Write a shell program to find the gcd for the 2 given numbers.
Ans.

192. Write a Shell Script for generating a mark sheet.


Ans.
LAB-25

193. Write a shell script to sort the given numbers in descending order using Bubble sort.
Ans.

194. Write a shell program to find the sum of the series sum=1+1/2+...+1/n.
Ans.

195. Write a Shell Script to read data from a file.


Ans.

196. Write a shell script to convert a file to lower case or upper case as specified by user.
Ans.

197. 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.
Ans.
198. Script to check given string is palindrome or not.
Ans.

199. Show the pattern using for loop


1
22
333
4444
55555
Ans.

You might also like