Top: Index Previous: Installing Up: Index Next: Scripting

CSC8306 -- Systems Administration

Essential Linux Commands

Previously, you should have installed a fully functional linux system. Turn the system on using VMWare Workstation and login. If you have forgotten your password or username, the you should follow these instructions 1.

For the next few sections, you will be learning to use the Linux Command line, and interacting with a shell. If you are used to windows, GUI environments only, this can come as a bit of a shock. Linux has, however, a highly functional command line. You can do most things directly through it. This has two critical advantage over a GUI. Firstly, is that it is easy to automate. From the last section, you will have realised that system administration requires a lot of sitting and waiting, unless you learn to automate things. Secondly, Linux is very modular; for most of our high-end, cluster machines the windowing software (called "X windows", or just "X" for short) just not installed. So a command line is the only option.

act
  • Go to Applications —> Accessories —> Terminal.
  • When the window pops up, maximise it. All the following commands should be typed directly into this window.

While typing commands into the Ubuntu window you might find it easier to use the local browser (firefox) to view these pages.

Basic Commands

Please remember that for most of what follows you are on your own; the answers to the questions are not in this documentation. You need to search, to find out for yourself. This is what Google is for!

logact Give short (10 word) descriptions of the purpose of the following commands. Please remember that if you cut and paste answers from external sources, then you must quote and reference them.

You should find the man pages very useful here. Try man touch, for example.

  1. touch
  2. ls
  3. cd
  4. pwd
  5. cp
  6. mv
  7. mkdir
  8. rm
  9. rmdir
  10. more
  11. wc

Next, you need to find how to move around the directory structure. Most of the commands that you need have been discussed earlier.

act
  1. Find out what the "root directory" means.
  2. Move to the root directory
  3. Move to your home directory (your home directory is referred to by the environmental variable $HOME)
  4. Using pwd, give the path of your home directory
  5. By moving between directories, and creating directories, create the directory structure $HOME/CSC8306/commanding
  6. From your home directory, remove with a single command, the directory CSC8306 and any subdirectories or files therein.
  7. Using a single command create the directory structure again
  8. Within the commanding directory, create the file file.txt

You will need to be able to edit files under Linux. During the course of this module, this will generally mean text files. There are numerous different editors that you can use 2. Probably the two most widespread are VI and Emacs. Both of these editors are extremely powerful, can operate through a terminal window or in a full windowing system. They are also both rather hard to use 3.

Try the command vi. If you wish to use Emacs, you will need to install it first using the synaptic package manager that will cover later (nowadays, typing emacs when it is not installed gives you a nice help message). Try launching it with the command emacs -nw, and it will run in a terminal.

act Edit the file that you created earlier. Add your name, and save the file. You need to be comfortable with your editing environment, so spend some time getting used to it. Most editors have integrated tutorials.

Files and Directories

Files or directories with related names can be acted upon as a group using wild cards

logact

For each of the following, write the commands that you used in your log book.

  1. In your home directory create the files cat.txt, car.txt, catfish.txt and bus.txt
  2. Move all these files to the $HOME/csc8306/phase2 directory
  3. List all .txt files
  4. List all files beginning with cat
  5. Remove the files car.txt and cat.txt

Environment variables

Linux systems have a number of "environment variables". These variables are often used to configure, or alter the way that the system works. These variables can be problematic, as there are quite a large number of them, often defined by individual applications. They can have quite a large impact on the system, can interact in unexpected ways.

act
  1. The export command is used to both set and view environment variables. Try listing all the variables on your system. Try man export for more information.
  2. Create a new variable called HELLO, with the value WORLD
log
  1. What is the function of the PATH variable?
  2. What command would you use to alter your PATH to include the directory $HOME/bin
  3. What configuration file would you use to set the PATH at each login.

Pipes and redirection.

When it was first created, pipes and redirection were one of the most innovative features of Unix.

All processes (programs, applications, daemons etc.) on UNIX have three means of communicating with the world.

Not surprisingly, there are several constructs that can be used to connect the input of one process to the output of another. This is called piping or redirection, as the output of one process is 'piped' or redirected into the input of another. There are several special shell characters used for common operations

logact Perform each of the following tasks, writing the commands that you have used to do so in your log book.
  1. create a file listing all files in the root directory, (if the file

    listing already exits, it should be completely overwritten)

  2. Do the same as above, this time appending the file
  3. Using the listing file you have just created as the input, count the number of files in the root directory (hint: a directory is a special type of file)
  4. In a single command, display the number of files in the current directory (hint, count the number of "words" in the "file")
  5. Finally count the number of files in the whole system

1. Sorry if this seems mean; there are ways of recovering lost passwords, and you can look them up if you wish. Ubuntu installs pretty quickly these days and doesn't ask many questions, so reinstalling is probably just as quick. There's also a lesson here. Don't lose your password.

2. Like the choice of Linux distribution, choice of editor is a highly religious topic. The argument between Emacs and VI has been raging for years. I'm firmly in the Emacs camp, but having some passing knowledge of VI is very useful as it's on every Unix system I have ever seen. At the very least, understanding enough VI to enable you to edit the files you need to install Emacs is very useful. Other options include, nano, microemacs, joe, jed and many others. If you include X based systems as well, the number gets higher.

3. If you think either of these editors is hard to use, try the ed command which was the original Unix editor.


Top: Index Previous: Installing Up: Index Next: Scripting