OS Assignment#1 Spring2020 PDF
OS Assignment#1 Spring2020 PDF
SCIENCES ISLAMABAD
ASSIGNMENT 01
Shell Scripting
Instructions
QUESTION NO. 01
where
and output the pattern depending on the input parameters as shown in Fig 1.
Generate error messages for invalid input parameter.
QUESTION NO. 02
Write a script that displays a main menu and perform tasks based on the in-
put value. Valid input values = {1, 2, 3, 4, exit}.
1. Input a filename from user and display permissions of that particular file.
Then invert the permissions e.g. If permissions were r-x change them to
-w-. Then again display the updated permissions of that file.
2. Input a filename and a string and search it in the file. Output the lines of
file where that string is found. But if the string contains a dot(.) it mean any
character can fill the place. For example:
string = c.t ={cat, cot, c t, }
3. Create a file dummy.txt and add the content of all the files in the current
directory to dummy. But copy the content in such a way that if
Then copy first N lines of files at even location {f2,f4,. } and last N lines of
files at odd location {f1,f3,. }. Input value of N from user.
4. Input a filename from user and check modified date of that file. If modi-
fied date is greater than 24 hours from the current time change the modi-
fied date to current date. Along with displaying the output on terminal,
maintain a logfile that contains the information of the script. Format of
the logfile is given on the next page:
2
Operating Systems Spring, 2020 NUCES, Islamabad
Option exit
Script terminated at date and time.
QUESTION NO. 03
Fig 2 shows the basic hierarchy of the files. Input (read) the name of the Main
Directory. In the Main Directory there are multiple directories Dir_1, Dir_2,...... ,
Dir_N. In each subdirectory there are multiple files with different extensions.
Now insert a loop that takes a string value as input and terminate when user
enter any string starting with e. The hierarchy of the files will change when user
will enter either forward or backward
3
Operating Systems Spring, 2020 NUCES, Islamabad
1. forward
Create 5 different directories namely java, txt, cpp, cc and other. Copy each
file in the directories depending on their file extension. Before copying the
file follow the protocol to name the file as DirectoryName-Filename.extension.
Delete all the extra folders from main Dir namely Dir_1, Dir_2,. , Dir_n.
2. backward
Now in the backward cycle, extract name of directories from the file name.
Create the directories again and copy the files to their original directory
restoring their default names.