Pathnames can be either ``relative'' or ``absolute''. An absolute pathname begins with a slash (/) and starts at the root. Each successive directory name down the path is also preceded by a slash. When you examined the shell's search path with the echo $PATH command in the previous chapter, you saw some absolute pathnames. The absolute pathname to the home directory for user ``person'' might look like this:
/home/personThe directory ``person'' contains the names of files in that directory, and it may also identify other directories below it in the hierarchy. ``Person'' is itself under the directory home, That is, the home directory is the ``parent'' of person; subdirectories below person are the ``children'' of person. This hierarchy is (in part):
(root) / | \ / | \ / | \ usr home <=== person's parent directory | | person <=== person's home directory \ \ htdocs <=== person's subdirectories / \ / \ / \ index.html welcome.html
A relative path starts from the directory you are working in and moves downward to a lower directory. Instead of starting with a slash, a relative pathname starts with the name of the first directory below this working directory; each lower directory down the path is prefixed by a slash.
In both absolute and relative pathnames, the rightmost component is either the ultimate directory name, or a file in that directory. For example, suppose ``person'' has two subdirectories: ``htdocs'' and ``stuff'', and ``welcome.html'' is a file in ``htdocs''. If ``person'' is the working directory, then here is a command to display ``welcome.html'':
cat htdocs/welcome.htmlAnother way to display the same file would use an absolute pathname:
cat /home/person/htdocs/welcome.htmlRemember that the C shell interprets ~person to mean ``the home directory of the user whose login name is person''. Thus, an equivalent command under the C shell would be simply
cat ~person/htdocs/welcome.html
lswhich lists the names of any files and directories that do not begin with a period (.). To see ALL the names, use the -a (all) flag:
ls -aEven if you have not yet created any files in your directory, you should see the names ``.login'' and ``.cshrc'' (the C shell's initialization files) and two entries named ``.'' and ``..''. The entry named only ``.'' is the directory you are working in, and ``..'' identifies its parent, even though these directories have full pathnames, too. All directories use ``.'' to refer to their own names and ``..'' to identify their parents.
To see how big your files are, and to see their protection modes, use the -l (long) flag:
ls -lThe protection modes determine what actions you and others may perform on the files. What these modes mean and how to change them is described below.
The -F flag is also useful. It marks the names of directories with a trailing slash (/) character and the names of executable files with a trailing asterisk (*). In fact, the command:
alias ls 'ls -F'is often included in .login and .cshrc files so that directories and executables are always indicated by the trailing characters.
To see directory information about selected files and lower-level directories, you can use the special characters described in chapter 4. For example, suppose you are ``person'' in the hierarchy shown above, working in your home directory, ~person. If you give the command
ls h*this expands to
ls htdocsand lists the names of files in the subdirectory ``htdocs'' except for files whose names start with a period.
To list the names of all files in the lower directory ``htdocs'', you might use
ls -a htdocsand get something like
. .. welcome.html index.htmlNote that this directory, like your home directory, uses . to mean its own name and .. to identify its parent. So to list the names of files in the directory above the current one, you could type
ls ..If you only need to know which files in subdirectory ``htdocs'' have names beginning with ``index'', you could use
ls htdocs/index* or ls htdocs/index[1-9] or ls htdocs/index?The last two forms would, of course, not list a file named ``index12''.
Note from these examples that the ls command lists files in the working directory only, unless you include the pathname to another directory whose filenames you want to list.
A common use of period is to separate a filename into two segments--a base and a suffix. Related files might be those with a common base name and different suffixes, such as
fortprog.f fortprog.oor with different base names and matching suffixes, such as
prog.c newsource.c test.cUsing the period this way, you can select sets of files for particular operations. For example, you could use *.c to select all files whose suffix is ``c''.
Certain programs such as compilers use filename suffixes to determine what action to take when they process files. Examples of this are in chapter 8.
Finally, no file or directory name can exceed 255 characters and no complete pathname can exceed 1024 characters.
mkdir namewhere name is the name of your new subdirectory. Suppose you call it ``to_do''. To make another subdirectory, named ``july'', below ``to_do'', you could use
mkdir to_do/julyspecifying the relative pathname from your home directory to the new subdirectory you are calling ``july''. Or you could move from your home directory to directory to_do first, then make july from there. By moving to subdirectory to_do, you make it your ``working directory''. To move to to_do from your home directory, use the cd (change directory) command:
cd to_doNow you can create the directory july below it by typing just
mkdir julyThis concept of ``working directory'' is very important. Whatever directory you are currently in is your working directory. Any time you use a filename with no pathname preceding it, that file is assumed to be in your working directory. Thus, if you start from your home directory and type
cd to_do/july cat project1then cat looks for file project1 ONLY in the subdirectory july, the new working directory. It does not look in your home directory or in subdirectory to_do. Likewise, if ``.'' is in the shell's search path, then the shell looks in your working directory for commands it cannot execute directly. This means that where the shell looks depends on where you are when you issue commands.
When you give the cd command with no arguments, it makes your home directory your working directory.
If you use cd very often to change working directories, you may need to be reminded where you are. To display the absolute pathname of your working directory, give the command
pwdwhich means ``print working directory''.
mv fromname tonameInclude the needed path information about the ``from'' or ``to'' directory if it is not your working directory.
For example, suppose you want to move file source.a from your home directory to the next lower directory, Mysources. If Mysources is your working directory, give one of these commands:
mv ~/source.a source.a or mv ../source.a source.aIf your home directory is the working directory, do it this way:
mv source.a Mysources/source.aThe mv command can also be used to rename files and directories. For example,
mv xyz abcsimply renames file ``xyz'' to ``abc'' in your working directory, since no directory change is involved. Similarly,
mv Newstuff Oldstuffrenames the directory ``Newstuff'' to ``Oldstuff'', without affecting the names or contents of the files in ``Newstuff''.
To prevent destroying a file that already exists, include the -i flag. For example, if you type
mv -i source.a oldsource.aand ``oldsource.a'' already exists, mv will ask if you really want to overwrite that old copy with the newer one.
drwx------ or -rw-r--r--The leftmost character is ``-'' for a filename entry, ``d'' for a directory name entry. The next 9 characters are three triplets of protection settings; the first pertains to you (the owner), the middle triplet pertains to members of your group (if a group has been established), and the rightmost pertains to everyone else.
Thus the first line shown here says the entry is a directory for which you have read (r), write (w), and execute (x) permission and for which everyone else has no privileges at all. The second entry is a file. In this case, you may read and write it, but others can only read it.
To change the protection modes of your files or directories, use the chmod (change mode) command. It has several forms, but the easiest to use is
chmod [who]oppermission nameswhere names identifies one or more file or directory names. The whooppermission sequence must be given with no blanks between portions. The who portion can be any combination of
u user (owner of the file or directory) g group members o others a all of the above (default if you omit the who argument)The op is one of
+ add the designated permission - remove the designated permission = replace all existing permissions for the relevant who with the new ones of this chmod commandand permission is any or all of
r read: If chmod is for a file, it allows that file to be read, provided the directory containing it has x permission. If chmod is for a directory, it allows that directory to be listed with filenames only. w write: If chmod is for a file, it allows that file to be written (altered or replaced). If chmod is for a directory, it allows new files to be added to that directory and existing files to be removed. x execute: If chmod is for a file, it makes that file executable (see chapter 10). If chmod is for a directory, it allows a detailed listing (if r is also set), and allows files to be read or written in that directory according to their individual file permission settings.The usual protection for a directory that you want others to be able to look through is r-x for everybody.
Examples:
chmod u=rx *.progpermits the owner of all files whose suffix is ``prog'', in the working directory, to read and execute these files. If write privileges had existed for the owner, these privileges are removed. No one other than the owner is affected, and no protection settings of any other files are affected.
chmod +r abstractgives everybody permission to read file ``abstract''. No other existing permissions are altered for the file. The directory containing ``abstract'' must have x permission as well, if attempts to read ``abstract'' are to succeed.
chmod +rx .gives everyone permission to read and search the working directory.
cat file1 [file2] ...To display files that take up several screens, you may want to use the command
more file1 [file2] ...The more program pauses after each screenful. At the bottom of the screen, it tells you how much of the file has been displayed so far. To see the next screenful, press the space bar. To see just one more line, press Return. For information about other options, type h. To quit without seeing the rest, press q.
If you just want to see the beginning of a file, use the head program:
head [-n] filewhich displays only the first n lines of the file. The default for n is 10. The tail command shows the last n lines:
tail [-n] file
cp fromfile tofile or cp file directoryThe second form copies a file to a new directory, keeping its original filename. The fromfile and tofile should include appropriate pathnames whenever the files are not in your working directory. Be sure that they are two different files.
Examples:
cp myfile Backup/myfile.oldcopies file ``myfile'' to the next lower directory, named ``Backup'', as a file named ``myfile.old''.
cp ~csaa123/report reportmakes a copy of file ``report'' from the home directory of user csaa123 and places it, with the same name, in your working directory. Since you are not changing the file's name, just copying it to the working directory, you could also have typed
cp ~csaa123/report .
rm file1 [file2] ...If you do not include a pathname, the files are assumed to be in your working directory. If you use any special characters such as * or ? with the rm command, it is a good precaution to add the -i flag, like this:
rm -i file*This interactive option displays, one at a time, each candidate for removal. To remove the file, type y (for ``yes'') and press Return. Any other response keeps the file.
Once rm has removed a file, that file cannot be retrieved: there is no ``undelete'' command. So you might want to put this command in your .cshrc file:
alias rm 'rm -i'This will cause rm to always use the -i flag, even if you type rm alone.
If you have a filename that contains one of the shell's special characters, rm might not be able to delete it. (A common case is accidentally creating a filename whose first character is a hyphen.) In this case, use the - flag and put the filename in quotation marks, like this:
rm - "badname"To remove a directory that you no longer need, use rmdir:
rmdir pathwhere path is the relative or absolute pathname of the directory. The rmdir command will not delete a directory while it is your working directory, nor will it delete a directory that contains any files (besides . and .. ).
To remove a directory AND any files and subdirectories it contains, as well as files in those subdirectories, use the ``recursive'' switch with the rm command:
rm -r path
Be Careful--Without also using the -i switch, it's possible to quickly delete entire directory structures. To be safe, userm -ir path
setenv PATH ${PATH}:$HOME/actionsHere ${PATH} means the current value of your search path and $HOME means the name of your home directory. In this case, you have made $HOME/actions the final place the C shell will search. To make the C shell look there first, reverse the positions of $path and $HOME/actions. Put the setenv command in your .cshrc file to make it take effect every time you log in or start a new copy of the C shell.
You may also need to set the PATH variable if you want to use a program outside your own directories and also outside the default search path. For example, a collection of programs to convert graphics files from one format to another is in the directory /usr/local/pbm/bin. To call up any one of these programs without having to give its full pathname, you could add /usr/local/pbm/bin to your search path.
Note: Much of the optional software commonly used on UNIX systems is installed in/usr/local/bin or /usr/local/gnu/bin
The most serious reason is that if you continue using resources, you may reach the ``hard'' quota. If you do, you will not be able to run programs. In fact, a running program will abort if it attempts to use disk space that exceeds the hard quota. Furthermore, when you try to modify existing files, they may get truncated to zero-length files--without warning or notice.
The second reason is that even if you do stay below the hard quota but remain over the soft quota for seven days, you will not be able to alter existing files or create new ones until you get back below the soft quota.
To see how much disk space you are using, give the command
quota -vIf you need a higher disk quota than the one originally established, please send email to: support@hardlink.com. There is a charge of 50 cents/meg/month for every meg over 15 megs. Keep in mind that you are charged for the disk space you reserve (i.e., your quota), rather than the disk you actually use; so don't request too much more than you expect to need.