More Unix Commands

The following commands are often used in the format listed. For more information, check out the man pages. The items in italics are the items that you fill in.
Displays the current date and time

gzip filename
Zips up the file called “filename

gunzip filename.gz
Unzips the file called “filename.gz

which program_name
Tells you the location of the program named “program_name” (ex., which date) that you are using (when you do not specify the entire path to the program; typing date vs. /bin/date at the command line).

whereis program_name
Basically the same as which.

mkdir directory_name
“Make directory”; creates a new directory, named “directory_name

cp filename filename2
“Copy”; copies the file named “filename” as the name “filename2“. When used in conjunction with pathnames, this allows to you copy a file from one location to another; ex., cp ~/file.txt ~/subdirectory/file/txt

mv filename filename2
“Move”; moves the file named “filename” to “filename2“. This is a convenient way to rename files; if you specify the pathname, you can move the file from one directory to another.

ln -s original_filename link_name
Creates a soft link to a file, called “original_filename“, and names the link “link_name

cat filename1 filename2
“Concatenate”; adds the contents of “filename2” after “filename1” and prints the output to the screen.

cat filename1 filename2 > filename_combined
Same command as the previous one, except this time, it saves the output to a file named “filename_combined” instead of printing the output to the screen.

less filename
Basically the same as the more command, but you have more options with less that you do not always have with the more command (for instance, many versions of the more command do not give you the capability to go backwards, but you can move backwards using the less command)

head filename
This command is the opposite of the tail command. By default, this command displays the first 10 lines of the file you specify.

wc filename
“Word Count”; this command displays 4 columns of information:

  1. Number of lines in the file(s); use the “-l” switch to display only this information. Ex., wc -l filename
  2. Number of words in the file(s); use the “-w” switch to display only this information. Ex., wc -w filename
  3. Number of characters in the file(s); use the “-c” switch to display only this information. Ex., wc -c filename
  4. The name of the file

sort filename
Sorts the lines of “filename” according to the first column in the file. So, if you have a file which contains a list of names with social security numbers to the right of the name, if you use the sort command without any switches, the file will be sorted according to the names listed in the columns on the left; the output is printed to the screen.

diff filename1 filename2
Compares the two files, and prints out the differences between them; the default is to print the output to the screen.

Return to index of lessons.

Last revised May 3, 2002.