Table of Contents
Return to Operationg Systems home
Operating Systems Course: Lab01
Laboratory number 01
Exercise 01: Management of files and directories
Part 01
Produce the following tree of directories in your home directory:
osEx01
|
------------------------
| | |
src bin test
| |
---------- -----------
| | | |
include lib script results
Part 02
- Download the file: lab01e01in.txt
- Copy the file in the directory
src, then, using the directorysrcas the current directory, copy the file in the directoriestest,script, andresults(to this extent use only absolute paths). - Check the existence of the files previously created, and check their rights.
- Use the commands
more,lessandcatto verify the content of the files. - Use the command
diffto verify that all the files have the same content. - Without changing the current (working) directory, cancel using relative paths all the files previously created.
- Repeat the same sequence of operations starting from father directory of
src, i.e.,osEx01.
Part 03
Executing all the commands from the root of your user (i.e., /home/username), do the following:
- Copy all the directory tree named
osEx01into a directory tree namedosEx01backup, by using the commandcpto copy individual files and the commandmkdirfor directories. - Cancel all the content of
osEx01by using the commandrmto remove individual files and the commandrmdirfor directories“. - Repeat both the copy and the cancel operations by using the recursive versions of the commands
cpandrm.
Part 04
Check what they do and for what the following commands are used:
pwdwchistory
For any problem, remember that you can use the following command to obtain an online help manual for a specific command:
man <command>
Exercise 02: Permissions management
Verify and reply to the following questions:
- the
usernameand thegroupto which you belong.
Is it possible to modify them? - the position of your home directory within the file system hierarchy of the system you are using
- the structure of your
/homedirectory (e.g., its subdirectories, etc.) - the rights of reading and writing on the various directories of the file system. Is it possible to modify access rights to your
homedirectory? - what happens if reading or execution rights are eliminated for a directory. Use both the octal notation (e.g., “654”) and the one based on characters (e.g., ”+uw-gx“) to modify the rights.
How is it possible to modify in the same way the access rights to all the files and directories of a directory tree (for example, to eliminate the read right to all, user, group, and other of the directory osEx01backup)?
Esercise 03: Link and comparisons between files
- Download the file lab01e03in.txt
- In the same directory where the file is stored, you have to create:
- A copy of the file with the name
lab01e03in.copy - A hard-link to the file with name
lab01e03in.hl - A soft-link to the file with name
lab01e03in.sl
- View files information with the command
ls -l- What can you see in the second column of the output?
- Why don't all the files have the same size?
- Check that the content of the three created files is the same as the original file using the
diffcommand.- Why does the
lab01e03in.slfile have a different size than the others, but it has the same content?
- Open and modify the content of the file
lab01e03in.txtwith a text editor of your choice- How do you expect information related to the size and the date of last modification of the file will be changed? Why?
- Verify your answer using the command
ls -l - What changes are expected regarding the content of the files? Why?
- Check the response by comparing the three files created with the original one. Use again the
diffcommand.
- Rename the file
lab01e03in.txtinlab01e03in.backup- What can you see now from the output of the
ls -lcommand? - Compare the content of the file
lab01e03in.backupwith the content of the fileslab01e03in.hlandlab01e03in.sl. Why in the second case do you obtain an error message?
- Create a new empty file named
lab01e03in.txt- What is the current expected content of the file
lab01e03in.sl? Why? - Check with the command
cat
Observation:
The command
touch <nomefile>
allows to update date and time of the last modification performed on a file.
In the case the specified file does not exist, it creates an empty file with that name.
Exercise 04: C programs and compilation
Perform the following tasks using:
- an editor of your choice (e.g.,
vim,emacs,gedit, etc.) - the
gcccompiler (alternatively use an IDE of your choice, e.g., CodeBlocks).
Part 01
Write a C language program that, using the ANSI C I/O primitives (fgetc/fputc, fscanf/fprint,fget/fputs of your choice), is able to copy a text file to an identical file.
The name of the two files is received on the command line, so that the program can be executed using a command that specifies three parameters:
nameExcutable sourceFile destinationFile
Part 02
Compile the source files using gcc
- Eliminate possible warnings.
- Try to compile the file by directly generating the executable, or first the object code and then the executable.
- Run the program using the lab01e01in.txt file as a test file.
- Verify the program using as program arguments both relative paths and absolute paths to specify input and output files.
- Verify the correct copy of the files (i.e.,
sourceFileanddestinationFilemust be identic) using the shell commanddiff.
Part 03
How does the written program behave if you try to copy a binary file?
- Use the object file or the executable file of the program written to perform a check.
- Test its correct functioning using the
diffcommand.
Part 04
Change the program using
- ANSI C
freadandfwritefunctions (optional) and then open,read,write, andclosePOSIX system calls.- Test its correct functioning using the
diffcommand.
Exercise 05: Compilation and makefile
- Compile the program of the previous exercise using a Makefile containing only the compilation target.
- Edit the previous Makefile by adding the
installtarget, which allows to- create a directory, sibling of the work directory and named
bin - move the created executable in this directory
- Edit the previous Makefile by adding the
cleantarget, which removes the object file in the current directory - Edit the previous Makefile by adding the
distcleantarget that calls thecleantarget and deletes thebindirectory (which is the sibling of the current directory) and all its content - Edit the previous Makefile using variables to specify the compiler, the compilation options, and the file name.
Take as reference the example analyzed in classroom: Makefile4
If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it
You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/os/lab01
