Tutorial: Basic Unix



1.1 Linux desktop

1. If you have never used Linux before, spent a few minutes familiarising yourself with the Desktop environment.


1.2 Editing files

2. Editing a file in Unix with pico:

      pico FILENAME

where "FILENAME" is the name of a new file containing just letters and numbers, no spaces.


1.3 Working with files

3. Viewing existing files:

      more FILENAME
      cat FILENAME

Most likely you won't see much difference between "more" and "cat". You'll need a larger file to see what the difference is.

      man man > fileX

(This creates a larger file called "fileX" which has the manual page for "man" as content.)

      more fileX
      cat fileX
      head fileX
      tail fileX

4. Renaming, copying and comparing files

"ls" is used to list all the files in your current directory; "mv" is used for renaming; "cp" for copying;

      ls
      mv fileX fileY
      ls
      more fileX
      more fileY
      cp fileY fileZ
      ls
      more fileY
      more fileZ

      diff fileY fileZ

5. Viewing file properties

The following two commands show file properties

      ls -l
      file *

6. Removing files

"rm: is used to remove files. Several of the Unix commands have a "-i" option, which inquires if you really want to execute the command before it executes it.

      rm -i fileZ

7. Review question


1.4 Working with directories

8. Try the following commands. If you cannot determine what these do type "man ls" and scroll down to where the options "-l", "-t" and "-a" are explained. To exit a manual page type "q". Type "man pwd" for information about "pwd".

      ls
      ls -l
      ls -l -a
      ls -l -t
      pwd

9. Searching for information

The following commands can be used for finding files, programs and file content. (This exercise assumes that you still have a copy of the man man page saved as fileY, see exercise 3.)

      find . -name 'fileY'
      which ls
      grep 'manual pages' fileY

10. Creating and deleting directories

Directories can be created with "mkdir" and deleted with "rmdir". By default all activities apply to the current directory. "pwd" shows the current directory. "cd" is used to change to a user's home directory. With "cd DIRECTORYNAME" one can change to the directory named DIRECTORYNAME; with "cd .." one can move to the parent directory of the current directory. The current directory is referred to by "."; the parent directory by "..".

      letters
      work
            progs
            tutorial
            misc
      script


1.6 Summary

Below is a list of all the commands you learned so far. Read through the list and check that you understand what each command does.


1.7 Users and System Information

Here are a few more Unix commands. These are useful for displaying information. Execute each of these commands and see if you can figure out what they mean (if not have a look at the corresponding man pages). There is much more to Unix administration than these commands, but viewing information about the system and its users is an important first step.

Unix Challenge

Here are some questions for those people in need of a more difficult challenge. Do not worry if at this state you are struggling to reach here, as in later tutorials even questions like these will become obvious to you.

  1. List the commands which have been recently executed and contain 'rm'.
  2. Write a Unix command that prints all files (not directories) which have been changed during the last 24 hours. (More difficult: Write a Unix command that copies all files (not directories) which have been changed during the last 24 hours to a directory called "backup").
  3. Change the 'rm' command so that instead of removing files it moves them to a hidden directory called 'trashcan' under the user's home directory.