Audience: Students, staff, faculty
Introduction
Learn about the top 10 common Unix commands.
- Text that is in square brackets, [ ], indicates a set of options that can be used with a command.
- The commands referred here will work on Unix systems operated by Information Services and Technology at the University of Manitoba. Some of these commands may work differently or may not be available on other Unix systems at the University or at other locations.
The man command will display the manual pages for most UNIX commands. For more information on any of the Unix commands below, use this to see if there is an online manual page available. For example, if you require help on the move (mv) command, you would type:
man mv
The command syntax for man is:
man commandname
By default, the man command uses another command called more to display the manual page one screen-full at a time. To display the next screen, press the space bar. To end the display before the end of the file, press the "q" key.
The Unix man pages are also available on-line from the Suns Document Pages.
Use this command to list the contents of the current directory. This will display all files and directories within the current directory in a columnar format.
You may change the format in which ls displays your directory listing by adding options to the ls command. To add an option to the command, follow the ls command with a minus sign '-' and the option(s) you wish to add. For example, ls -l will list the current directory in long format, showing size, date, and permissions. ll is a common alias or shortcut for the list long command (ls -l).
In Unix, there are files which are normally hidden called "dotfiles". These dotfiles are files that start with a dot (i.e. a period - ".") and are used by programs and shells to retain control information such as preference settings and bookmarks. To see hidden files, use ls -a to list all files, including those files whose names begin with a period. Be careful not to remove dotfiles if you're not sure of their purpose.
The command syntax for ls is:
ls [-aAcCdfFgilLqrstux] filename
If you use the ls command on a directory with many files, the display will probably scroll off the screen. To avoid this, you can "pipe" the display through the more command, just as with man pages. The Unix "pipe" symbol is a vertical bar (often a broken vertical bar on your keyboard). It means "take the command on the left, and use it as input to the command on the right". For example:
ls -la | more
Which lists the content of the current directory, in long format (-l) and includes all files (-a), and sends the listing to the more command which displays the listing one screen at a time.
For more complete information on the ls command, type man ls at the Unix prompt.
cd
The "change directory" command is used to switch from one directory to another. The purpose of having multiple directories is to enable you to easily organize your files. Your directory structure should resemble a filing cabinet, with folders (directories) for each set of files.
Using cd without a directory name following it will always return you to your home directory, no matter where you are in the Unix directories. To change to a subdirectory, for example one called "skiing", you would type:
cd skiing
To go "back up" a level in the directory structure from a subdirectory to its parent directory, you can use:
cd ..
.. is a special directory which always links a directory backwards to its parent directory, you can see this directory with the ls -a command. There is a second special directory called pwd, which always refers to the current directory.
The command syntax for cs is:
cd [directoryname]
For more complete information on the cd command, type man cd at the Unix prompt.
mkdir
The "make directory" command is used to create a new directory. As noted above, a directory serves to organize files similar to a filing cabinet. However, unlike most filing cabinets, a single directory may contain several subdirectories. For example, to create a directory called "Banff":
mkdir Banff
The command syntax for mkdir is:
mkdir directoryname
Fore more complete information on the mkdir command, type man mkdir at the Unix prompt.
"rm": Remove files command.
The "remove" command is used to permanently delete your files from your directories. To remove a file named "whistler.ps" from the current directory:
rm whistler.ps
To remove multiple files, use the remove command followed by the names of the files, separated by spaces. For example:
rm file1 file2 file3
The command syntax for rm is:
rm [-fir] filename
"rmdir": Remove directories command.
The "remove directory" command is used to delete your directories. The directory you wish to remove must be empty before using the rmdir command. To remove a directory called "bigsky", you would type:
rmdir bigsky
The command syntax for rmdir is:
rmdir directoryname
To remove a directory that is not empty (and all of its contents) you can use the rm command with the -r (recursive) option. This will recursively remove all files from a directory (or subdirectories) and then remove the directory itself. Repeating the previous example:
rm -r bigsky
More information
For more complete information on the rm and rmdir commands, type man rm and man rmdir at the Unix prompt.
The "copy" command is used to make a copy of a file in the same or a different directory. If copying to the same directory the filename of the copy must be different. This is useful for making backups or working copies of files while leaving the originals alone. To copy the file tahoe.txt to a backup file tahoe.txt.bak in the same directory:
cp tahoe.txt tahoe.txt.bak
To copy the file named "tahoe.txt" from your home directory to a directory named "goodskiing" (without changing the name):
cp tahoe.txt goodskiing
If you wish to rename the copied file:
cp tahoe.txt goodskiing/newname.txt
The command syntax for cp is:
cp [ -ip ] filename1 filename2
For more complete information on the cp command, type man cp at the Unix prompt.
The "move" command is used to move or rename files.
For example, to move a file named "panorama.ps" from your home directory to a directory named "goodskiing", you would type:
mv panorama.ps goodskiing
The "move" command can also be used to rename files or directories. If you wanted to rename a file called "mammoth.ps" to "BIG.ps" (remember that UNIX is case sensitive!), you would type:
mv mammoth.ps BIG.ps
Finally you can move and rename at the same time by specifying a new file name along with the directory to move to:
mv mammoth.ps goodskiing/BIG.ps
The command syntax for mv is:
mv [ -fi ] filename1 filename2
For more complete information on the mv command, type man mv at the Unix prompt.
Netscape and Lynx are two web browsers available on the Unix system. Netscape offers a graphical interface most familiar to browsers on other systems, while Lynx offers a text only browser interface. Lynx can be useful if you want quick access to information, or are using a text based terminal.
To start Netscape you must be logged into the CDE. Then type netscape at any Unix prompt, or click on its icon in the workspace menu.
To start Lynx type lynx in any Unix session. By default Lynx will startup displaying UM's home page. If you wish to have lynx browse a certain page once it starts, you can type:
lynx URL
Typing pine at the UNIX prompt will start up a simple but effective text base mail program. Pine allows you to receive, compose, send and organize e-mail messages, corresponding with anyone around the world who is connected to the internet.
Messages composed in Pine are edited using a file editor program called "pico" (for Pine Composer). The command pico can also be used from the UNIX prompt to create and edit other files. By default, pico will break up long lines between words, which gives a better appearance in most mail-reading programs.
To create a file called "filename" with pico type:
pico -w filename
Pine and Pico both have help features. For a more extensive introduction on Unix programs, see the Unix Software section.
Finger is used to display information about users on UNIX systems. Finger displays a user's full name, last login, and when the user last read their mail. If you wished to find out information about a user on campus, you would type finger username. If you wished to find out information about a user on the Internet, you would type finger username@host. You can also enhance the operation of finger by appending options to the finger command. For instance, if you know the person's full userid, you would then type finger -m username, which is much quicker than the normal finger command.
The command syntax for finger is:
finger [-mlsqibfwhp] [username]
For more complete information on the finger command, type man finger the Unix prompt.
Although old, the host command lets you learn about a machines 'host' information.
"dig": Get information about a host machine.
Although old, the dig command lets you learn about a machines 'host' information.
Additional information
- If you do not know the name of a file, but part of the name, you can use the * to signify the unknown part of the name. For example, to remove every file that ends in .ps, you would type
rm *.ps - UNIX is case sensitive!
- The Campus Bookstore has Dr. Salomon's Unix Cookbook, a great quick reference available for purchase.
0 Comments
Add your comment