In the following table, the angle brackets < > indicate variables you need to enter; don't type in the angle brackets themselves. Similarly, quotes (" ") are not typed unless this is explicitly stated.
| man <command> | brings up the "man pages"--the manual-- for the command listed. Ex: "man ls" brings up the man page for the ls command. This is a useful way to determine whether a function exits on the computer: if it exits, it will have a man page, and if it doesn't, you will get an error message. |
| pwd | "print working directory" Prints the absolute path to the directory you are in. |
| cd <path to new directory> | "change directory" Brings you to the new directory. You can use an absolute path, which always starts with /, the root. You can also use a relative path, that is, one starting from the directory you are now in. Relative paths don't start with /. |
| cd .. | Move up one level in the directory tree. cd ../.. moves up two levels, etc. Note there is a space between the "cd" and the "..". |
| cd ~ | Move to your home directory. |
| ls | lists contents of current directory, both files and sub-directories. |
| ls -l | Lists contents of current directory along with details about permissions, file sizes, last modification, etc. To get this list one page at a time, use "ls -l | more". That is, you pipe the output of ls -l to the "more" command. |
| ls -a | Lists all files in the directory, including hidden files. A hidden file is one whose name starts with a period (.). These files are not listed with ls or ls -l. To see all files with details, do "ls -al". |
| ls -t | Lists files in the directory sorted by the time they were last modified. In practice, "ls -lt | more" works the best: the newest files are at the top, and the file details are also listed. |
| cp <source> <destination> | Copies a file from the source file to the destination. If the destination is a directory name, the source file will be copied with its original name into that directory. If the destination is NOT a directory, the copied file will be given that name. Both source and destination can be relative or absolute paths. |
| mv <source> <destination> | Moves a file from source to destination. That is, the source file is copied to destination, then erased. This is usually used to rename a file. |
| rm <filename> | Removes (deletes) the names file. Be careful with this! Deletion is permanent. There is no "undo command". |
| mkdir <new directory name> | Makes a new directory below the directory you are in. |
| rmdir <directory name> | Remove (destroy) directory. The directory must be empty first. |
| chmod <3 digit number> <filename> | Changes permissions for this file. The three digits represent permissions for the file's owner (you), the group (you and the class instructor), and everyone else. Each digit represents 3 bits, for read, write, and execute permissions. A 1 bit gives permission and a 0 denies permission. Thus, the number 7 is 111 in binary, and gives read, write, and execute permission. A 5 is 101 in binary, and gives read and execute permissions. For most files you will want to use 750, giving you all three permissions, the instructor read and execute permissions, and locks everyone else out. However, files that need to be accessed through the internet will need 755 permissions, because access through the net is anonymous and open to everyone. |
| cat <filename> | Concatenate. Used to read the named file. If the file is long, cat <filename> | more can be used to read it a page at a time. cat -n adds the line number to each line. |
| more <filename> | Read the file one page at a time. Use the space bar to move down a page, and Enter will move down a single line. "q" is used to return to the command prompt. |
| less <filename> | Read one page at a time. The up and down arrow keys allow you to move backwards as well as forwards. |
| pico <filename> | Invokes the pico editor, a simple word processor with commands that are listed
on the screen and in the easily-accessed help file. It works well for reading files too. On some computers :nano" is used instead of pico. Most important commands:
|
| vi <filename> | Invokes the vi editor, which is quite powerful for a non-mouse editor. I don't like it much though. |
| control-C | Pressing the control key and the c key at the same time interrupts programs and returns you to the prompt. Very useful when programs are taking forever. It doesn't need to be a capital C. Control-D also works. |
| q | Pressing q returns you to the prompt when you are reading a long text program with "more" or "man". |
| ps -fu userid | THis prints a list of all processes "userid" is using. The process ID (PID) is listed; if you then type "kill 4567", the process with PID 4567 will be terminated. This is the way to stop runaway programs; you need to do it from another telnet (SSH) session. |
| grep 'short text' filename | grep prints out every line in "filename" that contains "short text". The -c option counts the number of lines with "short text" in it. |
| find <start_directory> -name "filename" |
Searches for the quoted filename, starting in the listed directory. It is common to use "/" to start at the root directory, or "." to start at the current directory. The man page for find has quite a few other useful options. |
| slocate <filename> | Finds where on the computer this file is. Sometimes the output is extensive, in which case slocate <filename> | more is useful. |
| > filename | Using the less than sign followed by a filename will re-direct the output into that file (where it can sometimes be more easily read). Note that this works for stdout; if you want the output for stderr (that is, error messages), use ">& filename". |