A brief Unix Primer

A list of common Unix commands


cd -- change directory

Our Unix/Linux computers are set up so that the command prompt tells you which directory you're currently in.

You can use cd to change into nested directories. For example, starting in the home directory, type

    ~>  cd html 
 cd lower

and (assuming that the html directory exists in your home directory and that the directory lower exists in your html directory) you'll see a prompt that looks like this:
  [gtowell@lasath lower]$ 
This line says "you login name is gtowell, you are logged in on the machine lasath and you are in a directory named lower"
To move up one directory, use the shortcut ".." for parent directory:
  [gtowell@lasath lower]$  cd .. 
   [gtowell@lasath html]$

To move up two directories, or more, use the parent of the parent:
  [gtowell@lasath html]$  cd ../.. 
   [gtowell@lasath home]$
This leaves you in a rather strange place (if you have been typing along) so for now enter "cd ~/html" (explanation forthcoming)
To move to a parallel directory, do something like this:
  [gtowell@lasath html]$  cd ../apr 
   [gtowell@lasath apr]$

To change to the home directory, use the ~ (tilde) abbreviation:
  [gtowell@lasath html]$ cd ~
   [gtowell@lasath gtowell]$
Also if you enter the command "cd" you will go back to your home directory. E.g.,
  [gtowell@lasath html]$ cd 
   [gtowell@lasath gtowell]$
    ~>
Finallym a dash is a shortcut for the last directory you were in:
  [gtowell@lasath html]$  cd ~/bin 
   [gtowell@lasath bin]$  cd - 
   [gtowell@lasath html]$

mkdir, rmdir -- make or remove a directory

mkdir new_directoryname
rmdir old_directoryname

Note that with this command, you can't remove a directory if it has any files or subdirectories in it.


ls -- list files in directory

ls filename[s]

Typing ls alone will list the files in the current directory. There are a variety of arguments to ls that give you more information about files.

ls -t sorts files by modification time (or date).
ls -l lists copious information about each file, including size in kilobytes and date of last modification.
ls -F appends a / to each directory and a * to each executable file.

Combining arguments can be useful:

ls -rlt sorts by and displays modification time (I find this one to be especially useful)
ls -F | grep "/" lists only directories.

Shortcuts

~ (tilde) stands for the home directory
. (single period) stands for the present directory
.. (double period) stands for the parent directory

* (asterisk) stands for zero or more of any character; alone, it means "all files in the directory"
m* matches all files beginning with m
m*.txt matches all files beginning with m and ending with .txt
? (question mark) stands for any single character in a file name