Simple Unix commands

In the examples text shown in bold type needs to be replaced by text of your own, for example your own username, or the name of one of your files.

Everything else should be typed literally as given in the examples, using lower- and upper-case as shown. (Almost everything in Unix is in lower-case.)

At the end of each command you must press the Return key.

Copying and moving files

When copying files from one directory to another you need to know for certain which directory is the current working directory. If you are not sure, use the pwd command.

Make a copy in the current directory

             cp oldfilename newfilename
             cp file1.html file2.html

Make a copy in a sub-directory of the current directory

             cp filename dir-name
             cp file1.html public_html
This will make a copy of file1.html within the public_html directory (assuming the directory exists).

Move a file into a sub-directory

             mv filename dir-name
The cp command makes a copy of the file with the new name or in the new location, and leaves the original file in place. If you use the mv command the file is moved, so the original is deleted and the only copy is the one in the new location.

Re-naming a file

The mv command can also be used to rename a file while leaving it in the same directory.
             mv oldfilename newfilename

Copying (or moving) to the parent directory

             cp filename .. 
             mv filename .. 
Note the space before the two dots. The two dots represent the parent directory.

Copying (or moving) from the parent directory into the current directory

You would use the following commands to copy or move a file from the parent directory into the current directory
             cp ../filename . 
             mv ../filename .
The dot at the end of these commands stands for the current directory. Note that there is a space in front of this final dot.

Copying a file into a sub-directory of a sub-directory

Suppose you have a sub-directory within your home directory called public_html, and within public_html you have a sub-directory called personal.

If you are currently in your home directory you can copy (or move) a file from your home directory into this sub-sub-directory with the following command:

             cp filename public_html/personal 
             mv filename public_html/personal
or if you wanted not only to move the file into the different directory, but also to give it a different name you could use this command:
             mv file1.html public_html/personal/file2.html

Julian Crowe
3rd May 1997
Simple Unix commands: contents page IT training page