www.thebits.co.uk

Commonly Used Commands

The reason why Unix has been kept off-limits to everyone but the gurus, is that us mere mortals can't make head-nor-tail, of the cryptic gibberish contained in those dreaded 'man' files. Time to put an end to this me thinks. Here then, are the most commonly used commands, in lovely plain english. Enjoy...

Note: All of the following commands must be entered in lowercase.

cd path

Description : Change directory i.e. move to another directory to work in it.
Examples : cd .. Move up to parent directory i.e. up 1 directory.
cd /usr Move to directory usr (1 directory down from root (/) directory.
cd my_work Move down 1 directory to my_work (a directory situated inside the current directory).
cd Move to the user's home directory e.g. /home/laurence (if user laurence was the user logged on and issuing this command).
cd - Move back to the last directory you were in.

ls options path

Description : Displays a directory listing.
Examples : ls Display a list of the current directory.
ls -f /etc Display etc directory with / after filenames to indicate sub-folders and *'s to indicate executables.
ls | more Display the current directory screen by screen i.e. 'piped' (|) to the more program.
ls | sort -r Normally ls sorts directory listing automatically, resulting in sort being pointless, however the -r switch reverses the order.
ls > list.of.files Creates a file called list.of.files containing a redirected (>) listing of current directory.
ls >> list.of.files Same as above, except this time the listing is appended to the end of an existing textfile - in this instance - the file, list.of.files
Options : -a List all files - including hidden files.
-l List all files details.
-f Indicate files, directories (/ after filename) and executables (* after).

mkdir directoryname

Description : Make/create a new directory.
Example : mkdir my_work Make a directory called my_work, in the current directory.

rmdir directoryname

Description : Remove/delete a directory.
Example : rmdir my_work Remove the directory my_work, contained in the current directory.
Note : You must first remove (rm) or move (mv) the files and subdirectories inside a directory before you can remove it. You are also not allowed to remove the current directory.

cp source destination

Description : Copies a file from one place, to another.
Examples : cp ~/hello . Copy file hello from user's home directory (~) to current directory (.).
cp hello goodbye Copy the file hello to a file called goodbye into same directory.
cp work/example play/example-backup A

mv source destination

Description : Move or rename, a file or directory.
Examples : mv letter old-letters/an_old_letter Move file letter from current directory to directory old-letters contained in current folder and rename file an_old_letter.
mv letter my_letter Rename file letter, as my_letter in current directory, because no path was specified.
Note : If you were to enter mv Budget Finance inorder to rename the directory Budget, as Finance and a Finance subdirectory exists in the current directory, then the Budget directory is moved to become a subdirectory of Finance i.e. /Finance/Budget. This could be both useful or annoying!

rm filename

Description : Remove file/s.
Examples : rm ~/text-files/my-text-file Remove the text file my-text-file.
Options : -r Remove all files in the current directory and all subfolders and their contents.
-i Confirmation prompt appears before a file is removed. This is advised when using wildcards e.g. rm a* (Remove ALL files in current directory starting with a.
Warning : If you enter say rm * .97 - to delete every file in the current directory that ends with .97, you would find to your horror, that you are about to delete EVERYTHING in the current directory. Why? - Because there's a space between the * and the .97 making the shell think you've entered rm *!!!

Note : Many more commands will be explained in plain english, within the next few days!

Laurence Hunter
thebits@thebits.co.uk