- Home
- Student Technology Collaborative
- Pantheon
- UNIX Advanced
Pantheon UNIX Advanced
The Unix file system is based on a hierarchal system of directories. Directories can be compared with folders on a Macintosh or directories in DOS. Basically, they provide a means of storing related files in the same place, away from other unrelated files. Directories are given names, just like files, and directories can contain other directories (called subdirectories). To show this, the parent directory is given, followed by a slash (/), followed by the child directory. For example, tax-files/march93/income could be the name of a file income, which is in the subdirectory march93, which is a subdirectory of the directory named tax-files.
In Unix, a user is always "in" a directory. To determine what directory you are in, issue the command pwd:
minerva% pwd /home01/staff/smith
pwd (Print Working Directory) shows you here that you are in the directory smith, which is a subdirectory of the directories home01 and staff. All users have a "home" directory, where their own personal files are kept.
To change directories use the cd command:
minerva% cd /home01/staff/baker
The user is now in /home01/staff/baker, or user baker's home directory. Using the command cd by itself will change you to your own home directory.
To create a new directory, use mkdir (Make Directory):
minerva% mkdir new-mail
This creates a subdirectory called new-mail in whatever your current working directory is.
To remove a directory (which must be empty), use rmdir (remove directory):
minerva% rmdir old-mail
Some basic subdirectories on a standard Unix system are listed below:
/bin Unix commands /etc Miscellaneous Unix files /tmp Temporary files; scratch space /usr/local/bin Locally-installed programs (pine, tin, etc.) /var/mail Incoming (unread) mail goes here /home User home directories
File Handling
Listing files and directories
On a Unix operating system, you use the command ls to give you a list of files in the current directory:
minerva% ls Mail/ News/ dead.article to-john
This shows that you have 4 files in your current directory; two regular files named dead.article and to-john and 2 sub-directories (signified by the trailing /) named Mail and News. You can get more information from a listing by giving ls additional arguments known as flags. For example, the flag -l (nearly all flags in Unix begin with a hyphen) gives you a longer listing:
minerva% ls -l drwx------ 3 tang 512 Aug 17 00:29 Mail/ drwxr-xr-x 6 tang 512 Aug 12 12:04 News/ -rw-r--r-- 1 tang 1032 Aug 09 11:59 dead.article -rw-r--r-- 2 tang 2113 Nov 26 1992 to-john
The first column with all the letters and dashes shows file (and directory) permissions (see File Permissions for more information). Note that the first letter of this column is a d for a directory and a - for a regular file. The second column indicates how many blocks that file takes. The third column shows the userid (on the Pantheon, this is a NetID) of the owner of that file. The fourth column is the number of bytes (characters) the files uses. Note that directories are usually assigned a fixed number of bytes in multiples of 512 based on the size of the files contained within those directories. The next three columns indicate the date and time that file was last modified. And the final column shows the file's name.
Files can also be "hidden" from regular ls by having the the file name begin with a dot. To see these dot files, you must include the -a flag with ls:
minerva% ls -a ./ .login Mail/ ../ .newsrc News/ .aliases .oldnewsrc dead.article .cshrc .pnewsexpert to-john
Here you see the current directory (.), the parent directory (..), six dot files, two subdirectories, and two regular files. Dot files usually contain information used for initializing certain programs, such as .newsrc, which contains a list of newsgroups for newsreaders.
Deleting files
To remove a file, use the command rm:
minerva% rm dead.article rm: remove dead.article: (y/n)? y
Renaming Files
To rename a file, or to move a file to a different directory, use mv:
minerva% mv to-john Newswill move the file to-john into the directory News
minerva% mv .login .logoutwill rename the file .login to .logout.
Copying Files
To copy a file, use cp:
minerva% cp .logout .login
will copy the file .logout to the file .login
minerva% cp .login Mail
will copy the file .login into the directory Mail.
Wildcards
There are two wildcards that can be used to match multiple filenames in Unix:
? matches any one single character.
mail? -would match "maila" and "mail#" but not "mail" or "mailtodave".
* matches any number (including zero) of any characters.
mail* -would match "maila", "mail#", "mail", and "mailtodave". You can also use *ail*, for example,
to match any file which has the characters "ail" in its name.
The one exception to both of the above is that an initial period (signifying a dot file) will never be matched by a * or ?. So ?login would not match ".login".
You can use wildcards for nearly any Unix command that accepts filenames as arguments: ls, mv, cp, rm, etc.
Startup Files
If you want certain commands executed every time you log in or start a new shell, you can put them into one of these files:
Note: These file names start with a period, or "dot".
.login: This is a file that is run only at log-in time. Among other things, the default editor is set here.
.cshrc: A file run as each shell is created, including at login time. The path is set here.
Accounts are created with default versions of these files. The files can be modified with any text editor. For example, to add a directory to your path, insert a line in your .cshrc like:
set path=($path directorypath)
You would replace "directorypath" with something like ~netid/bin, and this change makes it so than commands in the ~net/bin directory can be executed no matter what directory you are in.
If the shell cannot find a command in any of the directories in your path, an error message is returned:
% asdfjkl asdfjkl: Command not found.
After editing one of these files, type source filename to execute the changes, or log out and back in.
Stopped Jobs
The Unix operating system gives you the capability to be running a job, such as Tin, and suspending (stopping) it to run another job, such as Pine, with the intention that you will return to that stopped job.
If instead you try to logout, Unix reminds you that you have stopped a job (or jobs) earlier. In this situation, you need to either resume those jobs or kill them and then logout.
To resume a job, type fg to bring a stopped job back into the foreground. If you have multiple stopped jobs, type jobs to list them. You will get a list something like this:
minerva% jobs [1] Suspended tin [2] - Suspended finger @husc7.harvard.edu [3] + Suspended irc
The numbers in brackets are job numbers. To resume a particular one, type fg %x, where the x is the job number. In this example, to resume the command finger @husc7.harvard.edu, type fg %2.
Killing Jobs
If your computer crashes while you are logged into a Pantheon machine, or you have stopped jobs and wish to logout, it may be necessary for you to kill jobs. To do so, you should first take a look at what jobs you have running; you can do so by issuing the command "ps -fu your-userid":
minerva% ps -fu consult
UID PID PPID C STIME TTY TIME COMD
consult 26597 25879 80 20:20:15 pts/1 0:02 tin
consult 25879 25877 80 20:07:08 pts/1 0:02 -csh
consult 26759 25879 80 20:23:06 pts/1 0:02 ps -fu consult
Here you can see the three programs running for this user: "tin", "-csh", and the command just issued. "-csh" (or sometimes "-tcsh") is the "shell" program; it is the program that is run as soon as you log on, and it runs until you logout. In this case, the program "tin" is the job we wish to kill.
To kill the job, find the Process ID (PID) of the job. Here, tin's PID is 26597. Then use the kill command on that PID:
minerva% kill -9 26597
That will kill the job and allow you to logout without the "stopped job" message.