|
The UNIX file system is composed of two types of entities: files and directories.
Every file and every directory has a pathname which indicates where that file or directory lives
Unix Command | Description |
---|---|
The command cd (without an argument) moves you to your home directory. The command cd my_dir changes your position to the directory specified, in this case, my_dir. | |
The command cp first_file copy_file copies the contents of first_file into the file copy_file. To indicate that the new file is to have the same name as first_file, use a period (.) instead of providing a name for the second file. Example: cp some_directory/my_file . | |
The command exit is used for logging you off the machine when you have finished your session. | |
The command lpr print_file sends print_file to the default printer (see echo). The form lpr -Pother_printer print_file sends print_file to other_printer. | |
ls
| The command ls lists the files in the current directory. The form ls -F shows the difference between directories and ordinary files. |
The command mkdir new_dir creates a new subdirectory named new_dir in the current directory. | |
The command more my_file displays the text of my_file one page at a time.
| |
The command mv file_name dir_name moves the file file_name from the current directory into the directory dir_name. The form mv old_file new_file renames old_file and calls it new_file. | |
The command pwd prints the pathname of the current or working directory. | |
The command rm my_file deletes my_file. The form rm -i my_file asks if you want to remove the file my_file before it proceeds. | |
The command rmdir my_dir removes the directory my_dir. The directory must be empty before it can be deleted. Note: If you get an error message that a directory is not empty when it appears to be, check for invisible files (see ls). |
Unix Command | Description |
---|---|
echo
| The command echo MY_VARIABLE displays the current value of environment variables. Two variables of interest are $PRINTER and $DISPLAY. |
finger | The command finger user_name gives you information on the user whose name is specified by user_name. Note: The argument user_name can be the name of someone locally (i.e., jpower) or someone at a remote location (i.e., joeuser@vcu.edu). |
grep
| The command grep string filename searches filename for a string. It outputs every line which contains a string. The form grep -v string filename outputs every line which does not contain string. Note: The argument string is read by grep as a regular expression. |
kill
| The command kill my_process sends a terminate signal to the process specified by the process id (PID) my_process. In cases where the terminate signal does not work, the command kill -9 my_process sends a kill signal to the process. For information on getting the PID for a process, see ps. |
lpq
| The command lpq outputs the current queue for the default printer (see echo). The form lpq -Pother_printer outputs the current queue for other_printer. |
lprm
| The command lprm job_number removes job_number from the queue for the default printer (see echo).
The form lprm -Pother_printer job_number removes job_number from the print queue of other_printer. |
man
| The command man command displays the UNIX manual page for the command. |
passwd
| The command passwd allows you to change the password you use to login to the computer. |
ps
| The command ps lists the processes running on your machine. The form ps gux lists only your processes. The form ps aux lists all processes running on your machine. |
whois
| The command whois lookup_string performs a directory lookup on persons at your home institution. |
By convention, a UNIX command reads input from standard input (the keyboard). To get a command to read from a file instead, you need the command, the filename, and the character '<' : my_command < my_input. Think of the '<' as an arrow pointing in the direction the data is flowing, from the file to the command.
The output of a UNIX command is sent to standard output (the screen) by convention. To get a command to send the output to a file instead, you need the command, the filename, and the character '>' : my_command > my_output. The arrow analogy holds true in this direction as well, with the data flowing from the command to the file.
To append the output of a command to a file without erasing its previous contents, use the notation: my_command >> my_output.
If you have a series of commands in which the output of one command is the input of the next, you can pipe the output through without saving it in temporary files: first_command | next_command.
For example, if you wanted to print out a sorted version of a file that contained a list of names and phone numbers, you could use a pipe (as well as input redirection): sort < my_phone_list | lpr.
Note: The notation indicates that you should hold down the Control Key and then press the letter "c".
This article was updated: 04/27/2020