Useful Unix Commands

This document gives a few of the most commonly used Unix commands. These are simple commands that use issue to the computer to do things like move files or give you information. These are not ``software packages'', they are much simpler - merely instructions.

Definitions of Terms

We will need to use the following terms.

  1. File
    A collection of information associated with a file name.
  2. Directory
    A name of a collection of files.
  3. Subdirectory
    A directory inside a directory.
  4. Directory tree
    The name given to the arrangement of locations of files.
  5. Path name
    A sequential naming of all subdirectories within subdirectories.

Unix Commands

ls [ -alt ] [ subname ]
List files in the current directory and names of any subdirectories.
USAGE:
plato% ls no arguments
Simply list the files in the current directory.

plato% ls subname
When subname is a subdirectory name, you list all the files in the subdirectory.

plato% ls -l
List the lone version of the files which contains information about read/write permissions and tells which names are directories. Creation times are also shown.

plato% ls -a
List ALL files, even the ``hidden'' files that have a name beginning with a dot.

A good default is ls -aCF. It gives a multicolumn output for all files.

plato% ls -alt
gives all information about all files, -t tell the time when the files were created and orders files according to that time.

cp
Make and identical copy a file.

USAGE:
plato% cp file.a file.b
Copies file.a to create file.b with all the same information in the same directory. Two identical files result.

mv
Move a file from one location to another.

USAGE:
plato% mv file.a file.b
Move the contents of one file to another. The first ceases to exist and the second is created and contains the identical information as the original.

rm
Removes (deletes) files.

USAGE:
plato% rm file.a

The option -i asks if the file should be remove. For safety alias rm with rm -i in your .cshrc file


cat
Concatenate files.
USAGE:
plato% cat file.a file.b > file.c
This may be a bit technical, but here goes. Cat copies the standard input into the standard output. In general it is used as above, to combine two files head to tail, but it can also be used to edit small files, by giving the cat command with only one filename. When finished hit control-D.

mkdir
Make a directory.

USAGE:
plato% mkdir dirname
This would create a subdirectory named dirname in your current directory (i.e. the one you were in when you typed the command).

rmdir
Removes a directory.

USAGE:
plato% rmdir dirname
This removes an empty directory. if the directory is not empty, delete existing files first.

cd
Change directories.

USAGE:
plato% cd
When used with no arguments, it puts you into the home directory, i.e., the one you were in when you first logged on.

plato% cd dirname
This puts you in the subdirectory named dirname.

pwd

USAGE:
plato% pwd
Print working directory. No arguments are required. This tells you what directory you are in.

printenv
Print the environment variables.

USAGE:
plato% printenv
Environment variable are things that customize the characteristics of your account. It is not necessary to change these, but if you want to the command is setenv.

more
Print the contents of a file to the screen one page at a time.

USAGE:
plato% more filename
This command allows you to page though a file. While paging, hitting the space bar puts you on the next page. Hitting q gets you out of more.

grep
Search a file for a line contain a particular character string.

USAGE:
plato% grep string filename
This command prints the lines in the file named ''filename`` which contain the characters that you have chosen for the ''string''.

head
Show the head or first few lines of a file on the screen.

USAGE:
plato% head filename

tail
Show the tail or last few lines of a file on the screen.

USAGE:
plato% tail filename

clear
Clear the screen.

USAGE:

diff
Show lines of two files which are different.

USAGE:
plato% diff file1 file2
This command prints out the lines in the two files which are different. Each line is proceeded by a left or right arrow to indicate the left (file1) or right (file2) file that it came from.

man
Like a help command, but give the manual pages explaining Unix commands in detail.

USAGE:
plato% man cmdname
Here, cmdname id the name of the command that you want to know about.

logout
Last command you type to leave the system entirely.

USAGE:
plato% logout

These commands allow you to move around in the file system and look at what you have and make changes in it. These are the commands that you need to use between time that you are running a program or piece of software.