You are on page 1of 8

1. (i) (a) Use a command to display the whole calendar for the current year.

Do you need to type a


value for the year?
cal -y
(b) Use a command to get the calendar of the current month.
cal -1
(c) Use a command to get the calendar for the month of July in the year 2232.
cal -1 7 2232
(d) Use a command to find out which day of the week was the beginning of our
calendar (0001).
What was it?
cal 0001 (its Saturday)
(e) Use a command to determine if the year 2000 is a leap year. A leap year has 29 days in February
instead of 28?
cal -1 2 2000
(f) Use a command to determine if the year 1900 was a leap year.
cal -1 2 1900
(g) Compare the results of steps (e) and (f) and explain the difference.
Use the cat command to create and save the following file. Do not type headings. Call it ch6s4F1.
ID

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

(h) Use a command to show the number of workers.


wc l ch6s4F1
(i) Use a command to sort the field based on id.
sort +0 -1 ch6s4F1
(j) Use one single command to show the workers who is paid highest hourly rate.
sort r +1 -1 ch6s4F1
(ii) Write a shell script that computes the gross salary of a employee according to the following rules.
a. If basic salary is <1500 their HRD = 10% of the basic and DA=90% of the basic.
b. If basic salary is > - 1500 their HRA = 500 am DA = 98% of the basic.
(iii) Implement the character count data link layer framing method.

2. (i) (a) Check which group or groups you belong to.


groups
(b) 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 0077 and ls li file1 (file permission 600)
(c) Create a directory named chapter_4 under your home directory.
mkdir chapter_4
(d) Check the default permission of this directory. Is it 700?
ls li (default permission is 700)
(e) Create a directory under the chapter_4 directory (without moving from your home directory) and name
it session_1.
mkdir /home/baseer/chapter_4/session_1
(or) mkdir ./chapter_4/session_1
(f) Check the permission of this directory. Is it 700?
ls lid /home/baseer/chapter_4
(or) ls -lid ./chapter_4/session_1
(g) Move to the session_1 directory.
cd /home/baseer/chapter_4/session_1
(or) cd ./chapter_4/session_1
(h) Create a file named hw_4_1 under this directory and type the answers to (a)-(g) and save this file.
vi hw_4_1
press i
esc :wq
(i) Change the permissions to allow users in your group only to copy this file to their own directories. Is
there a need to change the permission of any directories? If yes, make the necessary change(s).
umask 0002 and chmod u+r hw_4_1
(j) Write a shell script that copies multiple files to directory.
(ii) Write a shell script which counts the number of lines and words present in given file.
(iii) Write a shell script using case statement to manipulate all arithmetic operations.

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)

Suppose there are following files in present working directory


art
Part
Part1
Part2
Part3
Tart
Quartz
Which of the above files would qualify for the following searches:
ls a?
no such files
ls a*
art
ls *.*
Displays nothing because only files with any extension will listed
ls [!abc]art
Part
Tart
ls [a-z]art*
Part
Part1 Part2 Part3 Tart
and ls (b-dku-z)* Nothing will displays because no such files between (b-dku-z)
(ii) Write a shell program to find:
a.
Total no. of files in directories and subdirectories.
b.
Total no. of block special character files.
c.
Total no. of directories.
(iii) Implement the byte stuffing data link layer framing method.

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

cat > ch6s1f1


(b) Use the cat command to display the file and check for accuracy.
cat ch6s1f1
(c) And use the vi command to correct any errors in the file.
vi ch6s1f1
(d) Use the sort command to sort the file ch6s1f1 according to the first field. Call the sorted file ch6s1f2. Print
the file ch6s1f2.
sort f +0 -1 ch6s1f1
(e) Use the cut and paste commands to swap fields 2 and 3 of ch6s1f2. Call it ch6s1f3. Print the new file
ch6s1f3.
cut f 1,3 ch6s1f2 >file1; cut f 2 ch6s1f2>file2; paste file1 file2
(f) Can we redirect the output to keyboard and redirect input to screen. What is the internal value associated
with the standard error device. >, < and 2
(g) What is the difference between the commands : wc l < file1 (Displays no. of lines without filename) and
wc l file1 (Displays no. of lines with filename).
(h) What is the difference between the commands: cat < file1 > file2 (Output of file1 is copied into file2) and
cat >file2 < file1 (output of file1 is copied into file2).
(i) List all files beginning with the character p on the screen and also store them in a file called file1.
ls p* > file1
(j) Display the list of last 20 files present in the current directory. Also store this list in a file Profile.
ls | tail -20
(ii) Write a Shell program to find average of n numbers.
(iii) Write a shell script to find the given number Armstrong or not.

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.

You might also like