Assignment 2
Assignment 2
LAB-2
35.
Ans.
LAB-4
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
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.
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.
57. Rename chap1,chap2 and chap3 to man1,man2 and man3 in your home directory.
Ans.
b)
59. What happens if you give the command mv progs newprogs1(After question 58).
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
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.
b.
c.
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.
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.
LAB-11
b)
c)
d)
LAB-12
107
.
Display the content of the addressbook in a single line i.e. join the lines of the file.
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.
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.
116. Sort the file file_emp and store the output in another file called file_emp1.
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.
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.
LAB-15
128. Display the content of the file file_emp3 in the following way:
DIPANKAR DAS
|
TEACHER
|
THA
…..
Ans.
131. Display all the lines except the lines containing TEACHER in the file file_emp3.
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.
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.
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.
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.
172. Shell script which whenever gets executed displays the message “Good Morning/Good
afternoon /Good Evening“ depending on the time it get executed.
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.
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.
180. Write a shell program to add, subtract and multiply the 2 given numbers passed as command
line arguments.
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.
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.
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.
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.