Practicum - week 9


Welcome to the first practicum!

0.

Log in and get acquainted with the terminal. Open more virtual terminals, konsoles, etc. Try pressing the middle button of the mouse to copy-paste a highlighted text. Try deleting with ^h. Close a virtual terminal with 'exit', as well as with ^d. (Remark: from now on ^ will refer to the CTRL button.)
 

1.

Read through the web page containing the information that you have to learn after the first lecture, if you have not done it yet. Most of the information should not be new, but some important details may not have been mentioned during the lecture, but have to be learnt. Furthermore, try to understand the examples mentioned on the web page; if you do not understand them, don't hesitate and ask us!


 

2.

Change your password with the command `passwd' (unless you have already changed your password in the past), and don't forget the new one!

Rule no. 1.: Never tell anybody your password!

If you tell somebody your password, and he or she does something illegal, then you will be liable. Nobody else can have access to your password. The system encrypts the passwords, so that even the system administrator (the superuser) is not able to find out them.




3.

The command echo simply writes its arguments to the screen. Try:

echo Hello, what a nice day!

As you remember, shell is the program that runs when you log in or you open a new (virtual) terminal, and it waits for your commands to execute them (or to run them). As shell is also a program, it is a file that has to be found somewhere in the file structure.

However, there are different shells, and maybe the file structure contains several files that can serve as shell. It is important, therefore, to be able to determine which is the file that actually runs as the shell. We will later speak about the variables in Unix. The variable $SHELL contains the path of the current shell running.

Check the shell you are using with:

echo $SHELL.
You should get something like '/usr/local/gnu/bin/bash'.

Try out typing the same, but changing the case, like 'ECHO', '$shell', etc. Use the upper cursor to save typing! Notice the different error messages.

What is the reason that if you type both an incorrect command (like 'Echo') with an incorrect variable name (like '$sheLL') you are told about the command, and not about the variable? Remember what we have said about the way the shell works (if you do not know, ask us).
 

4.

Check which directory you are in (use 'pwd'). List the content of this directory ('ls'). Walk within the directory tree using 'cd'. What does 'cd ..', 'cd ../..', etc. do? Always look at the prompt (= beginning of the line, printed by shell to the screen), and check if it really shows your actual working directory ('pwd'). Always list the actual directory, look at its content, and walk up and down in the directory tree.

Check also'ls -l' (long list). Does ls on Hagen use colour codes to distinguish directories from regular files? Remember that the first character in each line of the long list refers to the file type: - stands for a regular file, whereas d stands for a directory. In many systems the command 'll' is just a standard alias for abbreviating 'ls -l': try it out if it works.

If you are lost after so much walking in the directory tree, go home, i.e. to your home directory (simply by 'cd' or 'cd ~'), and check if you are really there (`pwd').

Go to the root directory (`cd /'), and try to find your way back to your home directory: list the directory in which you are, and try finding the correct subdirectory in which your home directory might be. If you want, look at the content of other directories.

While walking in the directory structure, try to draw the file tree on a sheet of paper. What directories are in the root directory? What files and directories are in these subdirectories? What directories and files do you have in your home directory? Who is the mother and who are the sisters of your home directory? Obviously, you don't want to represent everything, but get acquainted at least with the path from the root to your own home directory and its immediate neighbours.
 

5.

Now that you are back home, you can start changing the content of your home directory.  Make new directories (`mkdir'), check their content (ls) and remove them (rm, rmdir). Create files ('cat > filename') , check them ('ls', 'ls -l', 'cat filename') and remove them (`rm'). Check if you could successfully remove your directories and your files (`ls').

Try to remove a non existent file or a non existent directory. Try to remove a directory with 'rm' (without '-r'). What happens? Try to understand what the error message says exactly.

What is ~/.. ? Try creating a directory and a file in ~/.. ! Why does it not work?

(If you are not able to answer these questions, do not be shy, and ask us. They are not just rhetoric questions, and they may come up in the final exam.)

Note that UNIX doesn't give you any message if the task could be successfully executed, even if the result is not exactly what you had wanted to do! Therefore:

Rule no. 2.: Always check the effect of your commands!

The computer can execute only what you tell it to do, and cannot guess what really you meant. YOU have to be the smarter one, and imagine how the computer would interpret your commands. Using a computer needs a lot of empathy: put yourself in the place of the computer, since the computer is not able to put itself in your place. (For a counter-example, ask Lonneke about her research project :-) ...)


Play around with: cp, mkdir, mv, rm, rmdir, ls.

Use the TAB and the double-TAB to save typing the name of files and directories.

Try 'who', 'who am i', 'w', 'date' and 'cal'. (Don't forget 'cal 09 1752'!) Read the man-pages of the most important commands.

Get information on these commands using 'man <command_name>' and '<command_name> --help | less'. (Within man or less: use cursor-up, cursor-down and 'q' to quit.)
 

6.

Assignment to be shown to the instructor (or write the solutions on a sheet of paper and give it to us; or send your solutions in an email). Perform the following tasks, without changing your working directory (remember what you have just read about absolute and relative paths on the web site of the course):

  1. List the content of the root directory (give a command line that works independently of which directory you are in).
  2. Create a directory called `FruiTs' as a subdirectory of your home directory. Mind the difference between upper and lower case letters! The command line should work independently of your current location in the directory tree. Then create a directory called `My_favourite_fruits' within `FruiTs'.
  3. Move into the directory `FruiTs' in one step (a command line that is independent of your current location). From now on, you have to be within the directory `FruiTs' (= FruiTs is your working directory), and never quit it!
  4. Locate the file containing the shell (cf. 3), and copy it (that file) into `My_favourite_fruits'.
  5. Create a file `apple' and move it to your home directory.
  6. Copy the file `apple' from your home directory to the directory `FruiTs' (where you are currently).
  7. Rename the file `apple' that is in your home directory to `pear'.
  8. List recursively what you have in your home directory.
  9. Remove the directory `My_favourite_fruits'. (Does anything special happen?)
  10. The command `who' lists all the users who are currently logged in. The command `who am i', or simply `whoami' sounds funny, but actually it is quite handy when you have logged in under different names on different terminals, the prompt does not give you any useful information, and your are lost...
    Now, you want to get the number of users (# users) logged in. How do you check which option of the command `who' you need then? Which option is it actually?

In order to get maximal points, you should be able to present all these steps without help (so don't be lost within your directories, etc.). Obviously, before you finally show us your solution, you can ask for help. Try to make use of all tricks, such as copying a text with the middle button of the mouse, and by using ALT and the cursor-up buttons to save typing.

(10 points)

Closing remarks: when you have finished working in the Unix-room, you have to log out (otherwise people can misuse your account). Don't forget it. Nevertheless, never turn off a computer on which Unix is running! You may damage the whole system, and turning off the computer does not save much energy.