Simple UNIX Commands

ls

Lists the files in the current directory.

linux1[1]% ls -l

gives more information about the files. -l (the letter lowercase l not the number 1) stands for the "long" version. Here's an in-depth look at the ls command.

cp

Copies a file.

linux1[2]% cp sample.html example.html

makes a copy of sample.html and names the new copy example.html. [sample.html still exists.]

mv

Renames a file.

linux1[3]% mv average.html mean.html

changes the name of the file from average.html to mean.html. [average.html no longer exists.] Here's an in-depth look at the mv command.

rm

Removes or deletes a file.

linux1[4]% rm old-data.dat

would delete the file old-data.dat.

more

Types the contents of a file onto the screen one page at a time.

linux1[5]% more example.txt

would show the contents of the file example.txt one screenfull at a time. You must press the spacebar to advance to the next page. You may type q to quit or b to go back one screenfull. While viewing a file, pressing h will give you a help screen.

less

Types the contents of a file onto the screen one page at a time. It is similar to the more command but more robust.

linux1[6]% less example.txt

would show the contents of the file example.txt one screenfull at a time. You can press the spacebar to advance to the next page. You may also use the arrow keys to move up and down in the file. You must type q to quit. While viewing a file, pressing h will give you a help screen.

cat

Displays the contents of a file onto the screen all at once. If the file is too long to fit onto the screen, it scrolls. cat is also used to combine two or more files.

linux1[7]% cat mean.html

just displays the contents of mean.html.

linux1[8]% cat mean.html counts.html > statistics.html

concatenates the two files mean.html and counts.html by tacking the contents of counts.html onto the end of mean.html and calls the new, combined file statistics.html. [mean.html and counts.html still exist in their original form.]

mkdir

Makes a new subdirectory in the current directory.

linux1[9]% mkdir 104

will make a new directory called 104 in the current directory.

rmdir

Removes a subdirectory from the current directory, but the subdirectory must contain no files. You must delete all of the files from a directory before you are allowed to delete it.

linux1[10]% rmdir 104

will remove the directory called 104 in the current directory.

cd

The command cd alone will return you to your home directory. cd followed by a directory name that is found in the current directory, as in

linux1[12]% cd 104

will change from the current directory to its subdirectory called 104, if that subdirectory exists.

linux1[13]% cd ~jdoe1

will change to the home directory of the user named jdoe1.

cd ..

Moves you up one level in the directory tree. The .. means the parent directory.

pwd

Tells you the directory you are currently in.

lpr

Prints a file

linux1[14]% lpr sample.txt

would print the file called sample.txt on the DoIT printers found in Room ENG 019. There is a charge per page for printing.

man

Gives a description of a UNIX command and also C keywords and functions. So,

linux1[15]% man cat

will tell you all about the cat command. If you don't know the name of a command, but you do know what you want to do, use man -k. If you've forgotten the command for copy, you could type in man -k copy and you would be supplied with the name of the command (in this case cp) and a description of how the command works.

script

Begins a transcript of your Unix shell session. Everything that you type in and every thing that is printed to the terminal window is recorded in a file named typescript in the current directory. During the session being recorded, the typescript file is empty. You must exit from script (by typing the exit command) before you can access the contents of the typescript file.

who

Tells you the login names of all of the people that are currently logged onto the same computer as you are. They are not in any order and it will scroll off the screen.

|

"The pipe" is used to combine commands. It is the symbol on the same key as the forward slash. It "pipes" the output of one command to be used as input to the next command. Here's a typical use of the pipe:

linux1[17]% who|sort|more

This will give you all of the people's login names that are currently logged onto the same machine as you, in sorted order, one page at a time.