UNIX Survival Guide: A User Manual
|
The UNIX File System Structure
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
Files
- Files store information.
- There are many types of files.
- Two of the more common types are
- Text files -- which are files that you read
- Executable files -- which are files that you run
- Two of the more common types are
- If you choose the option "Save As..." at the bottom of the window, a dialog box will appear and prompt you for a "Name for the saved document:."
- If you type in a name and choose "OK," a text file will be created under the name you provided.
- Files with names starting with a period (i.e., .xstartup) are invisible in normal UNIX use.
- You can see them by using a variation of the ls command.
- Don't delete them. They are there (and invisible) for a reason.
- Filenames in UNIX generally do not contain embedded spaces.
- If you end up with a filename with embedded spaces, you can refer to it by enclosing the name in double-quotes.
Directories
- Directories organize files and other directories, creating the tree structure of UNIX.
- When you log in to your account, you arrive in your home directory, the root of your section of the UNIX file system tree. Your home directory, in turn, is a subdirectory within other directories in the file system.
Pathnames
- Pathnames specify files and directories.
- The pathname of a file indicates its location in the filesystem.
- Two files can have the same name as long as their pathnames are different. If you choose the option "Save As..." at the bottom of this window, the dialog box asking you for a filename will automatically fill in the pathname of your home directory.
- Example: A pathname for a user's home directory is /usr/jpower. The pathname for that user's mail directory might then be /usr/jpower/Mail.
- When you tell UNIX to look for a text file, it checks for that file in the current directory. If the file is in another directory, you must supply the pathname to the file.
Navigating the File System
Basic Unix Commands
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). |
More Unix Commands
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. |
Input and Output Redirection
Input
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.
Output
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.
Pipes
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.
Regular Expression
- A list of characters enclosed by [ and ] matches any character in the list.
- A list of characters enclosed by [ and ] with ^ as the first character matches any character not in the list.
- A range of characters can be expressed by separating the first and last characters in the range by a hyphen and enclosing them by [ and ].
- A period (.) matches any single character.
- A regular expression matching a single character (i.e., not a range) can be followed by a repetition operator:
- ? indicates that the preceding item is optional, matched once at most.
- * indicates that the prior item will be matched zero or more times.
- + indicates that the preceding item will be matched one or more times.
- {n} indicates that the prior item is matched exactly n times, where you specify the value for n.
- {n,} indicates that the prior item is matched n or more times, where you specify the value for n.
- {,m} indicates that the prior item is optional and is matched m times at most, where you specify the value for m.
- {n,m} indicates that the prior item is matched at least n times, but no more than m times; you specify the values for n and m.
Control Sequences
Note: The notation indicates that you should hold down the Control Key and then press the letter "c".
- Abort the current program or process.
- Exit xterm, ftp session, telnet session, gcg session, etc.
- Suspend execution of the current program or process.
- To restart execution in the foreground, type fg.
- To restart execution in the background, type bg.
This article was updated: 04/27/2020