This project is to help you getting familiar with Linux, which is, in fact, the operating system in the course title Operating System Labs. We will only cover two topics here, but we suggest that you play with it as much as you can. It is really fun and exciting. Although you will be stuck with this black annoying system at some point (almost surely), you can definitely learn something from this great software.
We first give you two simple tasks, and you will try to accomplish them with a few lines of shell scripts. Understanding some basic commands (cd, cp, ...) and concepts (redirection, pipe ...) is important. In the second part, you will practise with the C programming environment (gcc compiler, gdb debugger), which will be your best friends in the rest of the semester.
OSTEP Lab Tutorial
You need to write two shell scripts, both of them should be executable in a Linux shell.
s1.sh
:
% ./s1.sh foo
The script first builds a new directory foo
in the current directory (the one contains sh1.sh
), then creates two files: "name.txt" containing your name; "stno.txt" containing your student number. Finally, it makes a copy of "name.txt" and "stno.txt" in the same directory of foo
.
s2.sh
:
% ./s2.sh
It generates a text file output
. Each row of output
represents a file in directory /bin
, and contains three fields which are name, owner and permission of that file. The fields should be separated by white spaces. We further require that
output
should start with letter "b" (other file names should be excluded)output
is sorted by the file name field (in order of alphabet, from small to large)output
is read only for other usersThe following is an example of output
bacman root -rwxr-xr-x
badblocks root -rwxr-xr-x
baobab root -rwxr-xr-x
base64 root -rwxr-xr-x
basename root -rwxr-xr-x
bash root -rwxr-xr-x
bashbug root -r-xr-xr-x
bayes.rb root -rwxr-xr-x
bbox root -rwxr-xr-x
You need to compile/run a C program set_operation.c. The program contains several simple bugs, and you are going to detect and correct them using the gdb debugger.
Here are some details of the set_operation.c:
The program after being corrected should run as follows:
---------------------------------
----Computing (A-B)union(B-A)----
---------------------------------
----input the number of elements of A: 3
1-th element: 3
2-th element: 4
3-th element: 5
----input the number of elements of B: 2
1-th element: 1
2-th element: 4
---- elements of (A-B)union(B-A) ----
1-th element: 3
2-th element: 5
3-th element: 1
echo
and redirection to output some texts into a file.xarg
(between find
and ls
) or pipe.awk
maybe more convenient.sort
.When you need some details of a command, use man
. Output some informations properly when scripts are running. For example, for the second script, show the number of the instances of the file when it is created.
s1.sh
and s2.sh
.Try to use and get familiar with the shell commands first. Make good use of "man", "help" and "--help".
Start small, and get things working incrementally. For example, you can try to write some sub-functions in your script first, then test them before you combine them together. For debugging, you could build several test cases, and see why the running process of the program is different from your expectation.