Lab Report - 5 - OS
Lab Report - 5 - OS
Lab Report – V
Lab 5 & Lab 6
Subject:
Operating System
Submitted To:
Sir Zain Ul Abideen
Submitted By:
Muhammad Fakhar Ali
Roll Number - 2085
Program & Semester:
BSCS & 5th (Evening)
Lab Exercise No.5
Question No.1:
a. Use cd to go to your home directory, and create a new directory there called dog.
b. Create another directory within that one called cat, and another within that called mouse.
c. Remove all three directories. You can either remove them one at a time, or all at once.
d. If you can delete directories with rm -r, what is the point of using rmdir for empty
directories?
Answer: We do use rm -r to recursively remove a directory and all its contents, or when the
target maybe a directory or file and we want to delete it regardless of what it is. AND we use
rmdir to remove an empty directory.
e. Try creating the dog/cat/mouse directory structure with a single command.
Question No.2:
a. Copy the file /etc/passwd to your home directory, and then use cat to see what’s in it.
b. Rename it to users using the mv command.
c. Make a directory called programs and copy everything from /bin into it.
d. Delete all the files in the programs directory.
e. Delete the empty programs directory and the users file.
Question No.3:
a. The touch command can be used to create new empty files. Try that now, picking a name for
the new file: $ touch baked-beans
b. Get details about the file using the ls command: $ ls -l baked-beans
c. Wait for a minute, and then try the previous two steps again, and see what changes. What
happens when we don’t specify a time to touch?
d. Try setting the timestamp on the file to a value in the future.
e. When you’re finished with it, delete the file.
Lab Exercise No.6
Question No.1:
a. Type in the example on the cut slide to display a list of users logged in. (Try just who on its
own first to see what is happening.)
b. Arrange for the list of usernames in who’s output to be sorted, and remove any duplicates.
c. Try the command last to display a record of login sessions, and then try reversing it with tac.
Which is more useful? What if you pipe the output into less?
d. Use sed to correct the misspelling ‘enviroment’ to ‘environment’. Use it on a test file,
containing a few lines of text, to check it. Does it work if the misspelling occurs more than
once on the same line?
Answer: Yes, it does correct spellings of more than one words in the same line.
e. Use nl to number the lines in the output of the previous question.
Question No.2:
a. Try making an empty file and using tail -f to monitor it. Then add lines to it from a different
terminal using a command like this: $ echo "testing" >>filename
b. Once you have written some lines into your file, use tr to display it with all occurances of the
letters A–F changed to the numbers 0–5.
c. Try looking at the binary for the ls command (/bin/ls) with less. You can use the -f option to
force it to display the file, even though it isn’t text.
d. Try viewing the same binary with od. Try it in its default mode, as well as with the options
shown on the slide for outputting in hexadecimal.
Question No.3:
a.Use the split command to split the binary of the ls command into 1Kb chunks. You might
want to create a directory especially for the split files, so that it can all be easily deleted
later.
b. b. Put your split ls command back together again, and run it to make sure it still works. You
will have to make sure you are running the new copy of it, for example ./my_ls, and make
sure that the program is marked as ‘executable’ to run it, with the following command:
$ chmod a+rx my_ls