Useful commands

The started program operates from within your working directory, i.e. the directory where the command was exectued in. The unix directory structure is dissimilar to the directory structure you may know from a Windows operating system. In Linux, as in other Unix like operating systems, the directory structure is organized as a (partially fixed) tree with a single root node '/'. All directories and files in the directory tree are internal nodes or leaves of the tree. A path to a certain directory or file is a path along the tree, starting at the root node, where each change in the layer/depth is indicated by the '/'-character. Hence, a path like /usr/bin/test denotes, that starting from the root directory / there is a directory named usr that contains another directory named bin. In the latter directory then is a file named test.

To find out the current working directory there is the command pwd (print working directory). So finding out the current working directory will look similar to this:

$ pwd
/home/theochem
This directory is somewhat special as it is your so called home-directory. Home directories of users of a Unix based system usually reside in the path /home. The home directories are then named by the user account, e.g. theochem in your cases.

Changing the working directory to a particular path in the directory tree can be done by using the command cd (change directory), followed by the path, e.g.:

$ cd /usr/bin
Omitting the path and simply calling the cd command without it results in a change to the users home directory /home/username.

There are two special, reserved paths that can be used when browsing through the directory structures, '.' and '..', where the first denotes the current working directory and the latter its parent. So typing

$ cd ..
will change the working directory to the parent of the current working directory, i.e. we will navigate to the parental node in the tree.

The command ls can be used to show all entries within the current directory.

$ ls
prints the list of names of all files and directories. To get a detailed view of all files and directories of the current position in the directory tree, you can pass a so called parameter to the ls command. Parameters are usually following the command and start with one or two '-' letters. E.g.:
$ ls -l
will tell the ls command to create a detailed list view (parameter -l).

To get an overview of all available parameters of a program or command you usually can use the parameter -h or -help. Try this with the ls command:

$ ls --help

For a more detailed overview of the functions and parameter options of a command or program it is also useful to look inside the so called man-pages or manual-pages. This can be done by typing

$ man command

In order to use the directory structure, we need to be able to create and remove files or directories. It is also very useful to know how to change the name and copy or move a certain file or directory to another location. The command

$ touch filename
will create an empty text file named filename. To get rid of this file (remove it), you can use the command
$ rm filename
BE AWARE, that this command will really delete your file instead of moving it to some trashbin or something similar as you might expect. The file will be removed unrecoverable till eternity! Keep this in mind when using the rm command.

To create a new empty directory, you use the command mkdir (make directory).

$ mkdir butzemann
will create a new empty directory named butzemann. To remove a directory the command rm can be used again. However, the parameter -r must be passed to the rm command to indicate that you want to recursively remove the directory with all its content.
$ rm -r butzemann

Renaming files and directories is not done with a special rename command but with the move-command mv. The move command makes it possible to move a certain file or directory to another location. Imagine you have a file named foo and a directory named bar.

$ touch foo
$ mkdir bar
To move the file foo into the directory bar, the move command would look like this:
$ mv foo bar
This only works, if there is a directory called bar in the current working directory. If this is not the case and there is neither a directory bar nor a file with this name, the move command will rename the file foo to bar. So if the second path passed to the move command is nonexistant yet, the first path will be renamed to the second. This works for both, files and directories
$ mv foo bar

Copying files is accomplished by the copy command cp. Regular files source1, source2 and so on can be copied to a certain location destination in the directory tree by typing

$ cp source1 source2 source3 destination/

You can use as many source files as you like but make sure, that the target directory (destination) exists.

Copying directories to other locations is done by telling the cp command to recursively copy the given sources. Therefore use the -r parameter option:

$ cp -r sourcedir1 sourcedir2 destination/
As in the previous examples, always use the parameters -help, -h or man command to find out how to deal best with a certain command.

Ronny Lorenz 2010-04-06