Professional Documents
Culture Documents
UP Session Answers
UP Session Answers
Hourly Rate
Hours Worked
1420
12.56
45
3456
14.56
22
2341
45.12
34
1122
23.56
28
1443
23.23
19
2351
67.90
56
8001
7.00
14
3. (i) (a) Create and save the following file. Call it ch10s5f1.
This is a line with only one asterisk *.
*this is a line that start with starts with an asterisk, *but* has more.*
*** This is a line with three asterisks in a row.
This line has no asterisks.
This is another line with only one asterisk.
This Line has two asterisks * separated by other character. *
*** The start and end have three asterisk. ***
This line has two asterisks with *a* character between them.
*** The start has three, but the end has four asterisks. ****
*the start and end have one asterisk.*
(b) Write a command that finds the lines that start with one and only one asterisk. The line may contain more
asterisks, but it must start with one asterisk followed by a non-asterisk character.
grep ^[\*][a-z] ch10s5f1
(c) Write a command that finds the lines that contain two asterisks separated by another single character.
grep [\*][a-z][\*] ch10sf1
(d) Write a command that finds lines with six or fewer asterisks.
grep * ch10sf1
(e) Write a command that has an equal number of asterisks at the beginning and the end.
.
(f)
(g)
(h)
(i)
(j)
Mozart
(b)
(c)
(d)
(e)
(f)
(g)
(h)
(i)
(j)
4. (i) (a) Check which group or groups you belong to and check your default umask.
groups and umask
Create a directory called garbage under your home directory.
mkdir garbage
Check the permission of this directory. Make a note of it. Change your umask so that the default
permission is 664. What is the default permission of the directories after you make this change?
ls lid garbage ( 775)
umask 113
mkdir garbage1
ls lid garbage1(664)
Check the permission for garbage directory. Has it been changed after setting the default umask? Why
or why not? Delete this directory.
Not changed because it is created when umask value is 0002.
umask 0002
rmdir garbage
Create a directory called chapter_4 and create session_II directory under chapter_4 directory. Check
the permission of this directory and make a note of it.
mkdir chapter_4
mkdir ./chapter_4/session_II
ls lid chapter_4..(775..rwxrwxr-x)
Remove x permission for the user from this directory.
chmod u-x chapter_4
Move to session_II directory. You should have a problem. Do you know what the problem is? Fix the
problem.
cd ./chapter_4/session_IIPermission Denied
chmod u+x chapter_4
cd ./chapter_4/session_II
Create a file named hw_4_2 under this directory and type the answers for (a)-(g). Save this file.
vi hw_4_2.answers for (a) (g)
Check the permissions of this file. Can users in your group copy this file? Can they change this file?
Can users outside your group copy this file? Can they change this file? Is this file executable?
ls li hw_4_2.(rw-rw-r- -)
Yes, Yes, Yes, No and No.
Change the permissions of this file so that every user can read, modify, but not execute this file. Print
this file.
chmod o+w hw_4_2
(ii) Write a shell script to check whether a given number is Palindrome or not.
(iii) Write a shell script to check whether a given number is Prime or not.
5. (i) (a) Create three directories named letters, reports and assignments under your home directory.
mkdir letters reports assignments
(b) Move to directory letters.
cd letters
(c) Create two directories named friendly and formal under the letters directory.
mkdir friendly formal
(d) Move to directory reports using only one command (directly from letters).
cd /home/baseer/reports
(or)
cd ./reports
(e) Create three directories called personal, business and school under the directory reports (use only
one command).
mkdir personal business school
(f) Create a directory called unix under the assignments directory without moving from the reports
directory.
mkdir /home/baseer/assignments/unix (or)
cd ./assignments/unix
(g) Create two directories called HWs and PROJECTS under directory unix. The directories in this
step should be created without moving from the reports directory.
mkdir /home/baseer/assignments/unix/HWs /home/baseer/assignments/unix/PROJECTS
(or)
mkdir ./assignment/unix/HWs ./assignment/unix/PROJECTS
(h) Move to your home directory.
cd
(i) Recursively list all of the directories you created and draw the directory structure on paper.
ls R *
assignments:
unix
assignments/unix:
HWs PROJECTS
assignments/unix/HWs:
assignments/unix/PROJECTS:
letters:
fomal friendly
letters/formal:
letters/friendly:
reports:
business personal school
reports/business:
reports/personal:
reports/school:
(j) Use the umask command to set the default permission to be 700 for directories.
What is the default permission for files after this command?
umask 077 and for files permission is 600
(ii) Write a shell program to generate a multiplication table.
(iii) Implement the character stuffing data link layer framing method.
6. (i) (a) Use the cat command to create a file containing the following data. Call it ch6s1f1. Use tabs
to separate the fields.
1425
Juan
14.25
4321
George
21.11
6781
Anna
16.77
1451
Ben
21.77
2277
Tuan
18.77
7. (i) (a) Use the cat command to create and save the following file. Call it ch6s1f1.
ALPHABETICAL FACTS.
THE FIRST THREE LETTERS ARE ABC.
THE MEDIAN LETTERS ARE MN.
THE LAST THREE LETTERS ARE XYZ.
THE FIRST WORD IN MY DICTIONARY IS AAL
THE LAST WORD IN MY DICTIONARY IS ZYTHUM.
THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
THE LAST LETTER MAY BE PRONOUNCED ZEE OR ZED.
THE FIRST GREEK LETTER IS ALPHA.
THE LAST GREEK LETTER IS OMEGA.
cat ch6s1f1
(b) Use the cat command to check the contents. Use vi to correct any errors.
cat ch6s1f1 and vi ch6s1f1
(c) Using the translate command, encrypt this file by shifting each letter five characters to the end of the
character set. Use the cat command to check the contents of the encrypted file.
tr "[A-U][V-Z]" "[F-Z][A-E]" < ch6s1f1 > encrypt
(d) Now use decryption to decrypt the file. Call the new file ch6s1f1 (original file).
tr "[F-Z][A-E]" "[A-U][V-Z]" < encrypt > ch6s1f1
(e) Use cat command to look at the contents of the file. Is it the same as the original file?
cat ch6s1f1, YES
(f) Create 5 empty file empty1, empty2, empty3, empty4 and empty5.
touch empty1 empty2 empty3 empty4 empty5
(g) Create a file called text and store your name, age, sex and display the contents of the file Text on the
screen. Make a copy of the file text into another file new text.
cat > text
kkb
28
Male
ctrl+d
cat text
cp text newtext
(h) Create a file Matter and type any two sentences in it and combine the contents of the file Text and
Matter into another file TextMat. Delete the file Text.
cat >Matter
This is SVEC college
Tirupati
ctrl+d
cat text Matter > TextMat
rm text
(i) Create one more link called Tempfile for file Matter. Change the permissions for the file NewText to
666. Rename the file NewText to OldText.
ln Matter Tempfile
umask 0000
touch NewText
mv NewText OldText
(j) Create a directory MyDir in the current directory. Move the files OldText and Matter to the directory
MyDir. Create another directory Newdir within the directory MyDir.
Copy the contents of Mydir directory to the Newdir directory. Delete interactively all empty files
created earlier and Delete the directories Mydir and Newdir at one shot.
mkdir MyDir
mv OldText Matter ./Mydir
mkdir ./Mydir/Newdir
cp ./Mydir/Newdir/OldText ./Mydir/Newdir/Matter ./Mydir/Newdir
rm r mydir
(ii) Write a shell script check whether the two strings are equal or not.
(iii) Write a shell script to display the odd and even numbers to the specified range.
(b)
(c)
(d)
(e)
(f)
(g)
(h)
(i)
(j)
8. (i) (a) Create directories named letters, reports, assignments, formal, friendly, personal, business,
school, HWs, unix and PROJECT under your home directory.
mkdir letters reports assignments formal friendly personal business school HWs unix PROJECT
Recursively list the directories under your home directory(the ones created in session1)
ls R *
Move to the unix directory and check your current directory.
cd unix
pwd
Using vi, create a file named hw4 that contains questions with answers for (a)-(c) and save the file (it
should be saved under the unix directory)
vi hw4 give answer for (a)-(c).esc :wq
Move to your home directory and print the content of hw4 from your home directory.
cd
cat ./unix/hw4
Make a copy of hw4 and call it hw4.bk. Store it under the home directory where hw4 is stored. From your
home directory, check to see if both files (hw4 and hw4.bk) exist.
cp ./unix/hw4 hw4
cp hw4 hw4.bk
ls hw4 hw4.bk
Move to the unix directory and check your current working directory. Make a hard link to the hw4 file. The
link should be under the unix directory and be called hw4hl.
cd unix
pwd
ln hw4 hw4hl
Make a soft link to hw4 called hw4sl and store it under the unix directory.
ln s hw4 hw4sl
Check the inode of hw4, hw4.bk, hw4sl. Are all the same? Are all the different? Explain how you
determined the answer.
ls li hw4 /home/baseer/hw4.bk hw4sl
275039 -rw-rw-rw-. 2 baseer baseer 28 Feb 3 07:35 hw4
275041 -rw-rw-rw-. 1 baseer baseer 28 Feb 3 07:43 /home/baseer/hw4.bak
275043 lrwxrwxrwx. 1 baseer baseer 2 Feb 3 07:46 hw4sl -> hw4
Use the command ls find the file types of hw4, hw4.bk, hw4hl, and hw4sl. Explain your observation.
ls -li hw4 /home/baseer/hw4.bak hw4hl hw4sl
275039 -rw-rw-rw-. 2 baseer baseer 28 Feb 3 07:35 hw4
275039 -rw-rw-rw-. 2 baseer baseer 28 Feb 3 07:35 hw4hl
275043 lrwxrwxrwx. 1 baseer baseer 2 Feb 3 07:46 hw4sl -> hw4
275041 -rw-rw-rw-. 1 baseer baseer 28 Feb 3 07:43 /home/baseer/hw4.bak
(ii) Write a shell script to revere a number.
(iii) Write a shell script to display Fibonacci series.