Common Commands

The following is a very brief introduction to some useful Unix commands, including examples of how to use each command. For more extensive information about any of these commands, use the man command as described below.

cd

This command changes your current directory location.

cd ..

Changes your working directory to the parent of the directory that you are in when you issue this command. If you are at the root, you will remain there.

cd dirname

Changes your working directory to dirname. If you are not in dirname's parent directory, you must use dirname's full pathname.

^ Back to top

chmod

This command changes the permission information associated with a file ("change mode"). Learn more about viewing and modifying permissions in Unix.

^ Back to top

cp

This command copies a file, preserving the original and creating an identical copy. Because cp will overwite and destroy duplicate files, we recommend that you enter this command with the -i option, so that you'll be asked to confirm each file deletion.

cp file1 file2

Makes a copy of a file called file1 and names the copy file2. If there already is a file called file2, it will be replaced (overwritten).

cp -i file1 file2

Makes a copy of file1 and calls the copy file2. If there already is a file called file2, the system will ask you if you want to replace it before overwriting the file. 

^ Back to top

history

Lists your previous commands.

history n

Executes command number n in the list that you receive as output of the history command.

^ Back to top

less and more

Both less and more display the contents of a file one screen at a time.

Navigating:

  • Press the spacebar to scroll to the next screenful of content.
  • Tybe b to scroll back a screenful.
  • Type q to quit.

more filename

Lists the contents of the file called filename on your screen.

^ Back to top

logout

Logs you off the Unix system.

If you have a "stopped process" then the system will prompt you. Enter fg (foreground) to resume the process or logout a second time to abort the process and log off the system.

^ Back to top

ls

This command will list the files stored in a directory.

ls -a

Lists the files in your working directory and shows your hidden "dot" files, as well, including your .login file.

ls -l

Lists the files in your working directory, giving lengthier information about them—including file protection and access privileges.

ls -lt

Same as ls -l, but orders the files by time modified.

^ Back to top

man

This command displays additional information for a particular command. If you're unsure how to use a command or want to find out all its options, we suggest you use the man command to view the manual page.

Navigating:

  • Press the spacebar to scroll to the next screenful of content.
  • Tybe b to scroll back a screenful.
  • Type q to quit the man facility.

man -k key

Obtains online information when you don't know the command name. Replace key with a keyword for the function you wish to perform.

^ Back to top

mkdir

This command will make a new subdirectory.

mkdir dirname

Creates a directory called dirname. Your working directory will be the parent of this new directory, unless you specify another pathname.

^ Back to top

rm

This command will remove (destroy) a file. We recommend that you enter this command with the -i option, so that you'll be asked to confirm each file deletion.

Note: Using rm will remove a file permanently, so be sure you really want to delete a file before you use rm.

rm filename

Deletes a file called filename.

rm -i filename

Deletes a file after confirmation. Type y to confirm or n to cancel.

^ Back to top

rmdir

This command will remove a subdirectory. We recommend that you enter this command with the -i option, so that you'll be asked to confirm each file deletion.

rmdir dirname

Deletes a directory called dirname, if the directory is completely empty. If you're not in dirname's parent directory, you must use dirname's full pathname.

rm -rf dirname

Deletes a directory called dirname, and everything that is included in the directory. If you are not in dirname's parent directory, you must use dirname's full pathname.

^ Back to top

passwd

Initiates the password-changing program. Respond, as prompted, with your old and new passwords.

^ Back to top

pwd

This command reports the current directory path ("print working directory").

^ Back to top

vi

This command starts the vi text editor.

vi filename

Uses the vi editor to open a file called filename.

^ Back to top

Keyboard commands

To use the following common keyboard commands, hold the "control" key down while typing the letter shown next to it.

ctrl + c

Aborts the current process, for example a long screen listing.

^ Back to top

ctrl + z

Suspends the execution of a process ("a job"). To have the process continue in the background (type bg immediately after). Type fg to resume the job or bring it to the foreground. To kill a suspended job, type jobs, then kill %n, where n is the number of the suspended job.

Use of this suspend character should be avoided until you have some familiarity with the system.

^ Back to top