Table of Contents
Previous Chapter UNIX files are organized in directories, similar to the file folders discussed above. Directories are files, but instead of containing data or text as other files do, the directory contains information about other files. Directories are organized like inverted trees. The root directory named / is at the top. Branching out from the root directory are the rest of the directories. Any directory can contain both directories and other files.
All directories together are referred to as a file system. The SLAC UNIX file system is a single file system in one sense, that is, all directories originate directly and indirectly from a single root directory at the top. However, in another sense, we have two file systems: the Network File System (NFS) and the Andrew File System (AFS) that share that common root directory as shown in Figure 2. SCS started with NFS support and began moving toward AFS because it offers significant advantages over NFS.
The most notable difference between NFS and AFS is how file access permissions (that is, who is allowed to read, write, execute, etc. a given file) are implemented. The discussion "Handling File Security: File Access Permissions" on page 25 assumes NFS, not AFS. How file access permissions work in AFS is described in the document SLAC AFS Users' Guide. Hard copies are available at the SCS Help Desk. Be aware that even if your home directory is in NFS, you may still need to become familiar with AFS because most collaboration data space is in AFS and SLAC's production WWW space is also in AFS.
.
/quark/mary/george/source/sum.f
The first / signifies the root directory. Each subsequent directory name is separated by an additional /.
ilse@odysseus $ ypmatch ilse homes
ilse:/afs/slac.stanford.edu/u/sf/ilse
but user billie's home directory is in NFS:
ilse@odysseus $ ypmatch billie homes
billie:/nfs/juno/u8/sf/billie
------------------------------------ cp /quark/mary/george/source/sum.f . ------------------------------------In this case, the file /quark/mary/george/source/sum.f would be copied into the working directory /quark/paul. See "Copying Files" on page 21 for more information about the cp command.
The shorthand term for the directory one level above the working directory is two consecutive periods (..). For example, if your present working directory is /quark/paul, .. would refer to the directory /quark. You could use .. as an argument for the change directory command:
-----
cd ..
-----
Given a symbolic link, if you want to know the absolute pathname of the file, use the sl (show chain of symbolic links) command.
Example 1:
ilse@odysseus $ sl afs-slac
afs-slac:
afs-slac -> /afs/slac
/afs/slac -> slac.stanford.edu
slac.stanford.edu
Symbolic links to absolute pathnames (absolute pathnames start with a slash (/); relative pathnames don't) start over at the left margin. Symbolic links to relative pathnames are aligned vertically with the path element they replace. So the easiest way to read this sl output is to substitute slac.stanford.edu in the last line for the path element slac directly above it in the last and only absolute path /afs/slac yielding an absolute pathname of
/afs/slac.stanford.edu .
Example 2:
ilse@odysseus $ sl /usr/local/bin/environ
/usr/local/bin/environ:
/usr/local/bin -> bin.next
bin.next -> /a/juno/usr/local/bin.next
/a/juno/usr/local/bin.next -> bin.next-m68k
bin.next-m68k/environ -> ../bin.shared/environ.main
bin.shared/environ.main
To decode the absolute pathname in this example, substitute the last line,bin.shared/environ.main,
for the path element bin.next in the last absolute path /a/juno/usr/local/bin.next, so that it reads:
/a/juno/usr/local/bin.shared/environ.main
----------------------------------------------------------------------------------------
cd /nfs/juno/work Changes the current working directory to /nfs/juno/work
pwd Prints the working directory, that is, lists the name of the working
directory on the screen.
/a/juno/work The pwd command almost never shows the pathname exactly as
you would use it on the cd command. In this case
/nfs/juno/work is a symbolic link to /a/juno/work (see section
"Symbolic Links and the sl (Show Symbolic Links) Command" on
page 18).
----------------------------------------------------------------------------------------
Within your home directory are some files whose names begin with a dot (or period). Most users do not need to access dot files often. They do not show up on the list supplied by the computer when you type the ls command (assuming you do not use the option -a). Because they are not listed on the screen of your terminal, you can find other files more easily. Common dot files are listed in Table 3 below.
TABLE 3. Common Dot Files
-----------------------------------------------------------------------------------
.cshrc The system runs the commands in this file each time you start the C
shell. This varies, though, depending on the shell you use. Usually a
good place for alias commands. (See section 4.2.)
.forward Contains address(es) where mail for this account should be forwarded
(e.g., ilse@slacvx.slac.stanford.edu or simply ilse@slacvx).
.login The system runs these commands when you login. (See section 4.1.)
This varies, though, depending on the shell you use.
.logout The system runs these commands when you logout.This varies,
though, depending on the shell you use.
.plan Information you leave in this file displays when your username is fin
gered. (See section 8.2.)
.project Information you leave in this file displays when your username is fin
gered. (See section 8.2.)
-----------------------------------------------------------------------------------
---------------------------- Library/ Mailboxes/ memos/ $ ----------------------------ls -a lists all files, including dot files. The character / after a name indicates a directory; * after a name indicates it is an executable program.
------------------------------------- ./ .cshrc .newsrc Mailboxes/ ../ .kshrc .profile memos/ .NeXT/ .login Library/ -------------------------------------ls /usr lists the names of files or subdirectories in a directory other than the current one, here, /usr.
--------------------------------------------------- adm/ etc/ local/ prman/ standalone/ apps/ filesystems/ man/ pub/ template/ bin/ games@ netware/ share@ tmp/ cad/ include/ nfs/ shlib/ ucb/ dict/ lib/ preserve/ spool/ ---------------------------------------------------For more information about each file, use the -l option. ls -l lists each file or directory in the working directory, along with its permissions (security information), creator, size in bytes, and date of last modification.
total 12
drwxr-xr-x 9 ilse 2048 Aug 10 1994 Library/
drwxr-xr-x 2 ilse 2048 Apr 17 1995 Mail/
drwxr-xr-x 42 ilse 4096 Oct 20 1995 Mailboxes/
-rw-r--r-- 1 ilse 885 Apr 27 1994 datasave.opt
--------------------------------------------------------------------------------------
$ pwd Prints working directory (i.e., lists the name of the working
/a/juno/u8/sf/cathie directory on the screen).
$ cd .. Changes to the directory one level above. A double period is a
special name for the directory one level above.
--------------------------------------------------------------------------------------
---------------------------------------------------------------
$ mkdir test Directory name is test. You can specify the
directory by its absolute or relative pathname.
---------------------------------------------------------------
------------------------------------------------------------------------------------------
$ rmdir test In this example, the directory to remove is test. You can specify the direc
tory by its absolute or relative pathname.
------------------------------------------------------------------------------------------
After the source file is copied, it remains intact in the directory where it was located.
--------------------------------------------------------------------------------
$ cp sum.f sample.bak Copy the file sum.f. The name of the new copied
file is sample.bak.
$ cp /quark/paul/.cshrc . Copy the .cshrc file to the working directory. The
second period indicates the working directory.
--------------------------------------------------------------------------------
Unlike cp, if you move a file or change its name, the source file is deleted from its directory after the procedure is finished.
------------------------------------------------------------------------------
$ mv sum.f test.case
Gives the file sum.f the new name test.case (i.e., renames the file).
$ mv test.case /usr/smith/cases/test.bak
Moves the file test.case to the file test.bak in the subdirectory cases.
------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
$ rm test.case Removes the file test.case permanently.
$ rm -i test.case Remove the files test.case; requests confirmation.
rm: remove test.case? y Type y for yes or n for no.
$ rm -i test* A more instructive example of the use of the -i option is
this case, where multiple files begin with `test', some of
which you want to remove and some of which you don't.
rm: remove test.case? y
rm: remove test1.case? n
-------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
$ more memo Scrolls the contents of the file memo, screen by screen. Press the space
bar to display the next screenful. To return to the prompt, type q or hold
down the CTRL key and type c.
<contents of memo>
$
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------- $ grep Computing test.doc Searches test.doc for text string Computing. to carry out the SSCL mission. This plan introduces the Computing and The Computing and Communications Organization within Computing and Communications to concentrate efforts in these areas -------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
$ diff rose1 rose2 Displays differences between files.
< Violets are blue Line in rose1 differs from rose2.
-
> Violets are green Line in rose2 differs from rose1.
$ ilse@odysseus $ comm sg1 sg2 Comparison results of files sg1 and sg2 are shown in
abh three columns. The columns are offset by tabs. Column1
bobcook shows lines only in sg1 ; column2 only those lines in sg2;
esr column3 lines in both files.
joann
kls
les
ljm
lmwhite
meb
randym
renata
wcw
wglp09
-------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------
$ head /usr/local/doc/policies/password Displays the first 10 lines of the file
/usr/local/doc/policies/password
----------------------------------------------------------------------------------
This is file /usr/local/doc/policies/password.
This article on choosing good passwords is by Lionel Cons of group CN/SW at CERN. It appeared in CERN Computer Newsletter 210. Mr. Cons kindly allowed us to adapt it for SLAC users.
Introduction
------------
A good password:
-----------------------------------------------------------------------------------
$ head -5 /usr/local/doc/policies/password Displays the first 5 lines of the file
/usr/local/doc/policies/password
-----------------------------------------------------------------------------------
This is file /usr/local/doc/policies/password. This article on choosing good passwords is by Lionel Cons of group CN/SW at CERN. It appeared in CERN Computer Newsletter 210. Mr. Cons kindly allowed us to adapt it for SLAC users.
--------------------------------------------------------------------------------
$ tail /usr/local/doc/policies/password Displays the last 10 lines of the file
/usr/local/doc/policies/password
--------------------------------------------------------------------------------
together with a punctuation character between them (or a digit if you can only
use alphanumeric characters). For example: 'dog+F18' or 'comP7UTer'. Note that
'dog', 'F18' or 'computer' are in dictionaries but as the passwords use
punctuation or digits, mixed-case character, they are really hard to guess.
Remark: if you use mixed-case characters, do not use the following methods:
- all lowercase or all uppercase
- only the first or the last character in uppercase
- only vowels in uppercase
- only consonants in uppercase.
------------------------------------------------------------------------------------
$ tail -5 /usr/local/doc/policies/password Displays the last 5 lines of the file
/usr/local/doc/policies/password
------------------------------------------------------------------------------------
Remark: if you use mixed-case characters, do not use the following methods:- all lowercase or all uppercase
- only the first or the last character in uppercase
- only vowels in uppercase
- only consonants in uppercase.
--------------------------------------------------------------------------------------------
Class of User Definition
--------------------------------------------------------------------------------------------
user The user who owns the file/directory.
group The group of users who share access of a file. (Every user belongs to one or
more groups. To see what groups you are in, type groups at the prompt.)
Each file and directory "belongs to" one user and one group.
others All other users.
--------------------------------------------------------------------------------------------
Each file or directory has a set of permissions that control access to it. For each class of users above, there are three permissions that may be granted to that class for each file or directory. These are shown in the following chart.
-------------------------------------------------------------------------------------------------------
Permission File Directory
-------------------------------------------------------------------------------------------------------
read (r) Allows class to read the file. Allows class to list the names of files and subdi
rectories in the directory.
write (w) Allows class to modify a file Allows class to create and remove files and subdi
(e.g., to append to it or to trun rectories from the directory.
cate it).
execute (x) Allows class to execute a file. Allows class to access files in the directory if they
know their names.
-------------------------------------------------------------------------------------------------------
When you create a file or directory, it is assigned a default set of permissions, which you can change. With ls -lg, you can see the permissions associated with a particular file or directory as the first 10 characters on each line. (Be sure to use the correct absolute or relative pathname for the file or directory.)
--------------------------------------------------------------
$ ls -lg
drwxr-xr-x 3 ilse sf 1536 Sep 24 10:15 Telecom/
-rw-r--r-- 1 ilse sf 830 Aug 23 12:39 Unix-guide-questions
-rw-rw-r-- 1 ilse sf 353280 Sep 27 10:34 Unix-guide-
slac.block.frame
-rw-rw-rw- 1 ilse sf 353280 Sep 29 11:00 Unix-guide-
slac.block.frame.auto
--------------------------------------------------------------
The -g option shows the group to which the file or directory belongs; in this example, the group is sf. Note, however, that ls -lg means show the group on a Sun, but ls -l means show the group on an RS/6000. The first character indicates whether this file is a directory (d) or just a regular file (--). The next three groups, consisting of three characters each (nine characters total), are the permissions granted for the user, group, and others classes, respectively. A permission is granted if the letter is present and not granted if the (--) is there instead. Thus, in the example above, the file Unix-guide-questions is a regular file (--) that allows the user reading and writing privileges (rw- ), but limits the group and others to only reading the file (r- -).
$ ls -lg
total 12
-rw-r--r-- 1 bobcook sf 2847 Sep 6 11:42 groupfile
drwxr-xr-x 2 bobcook sf 32 Sep 6 11:41 privatedir/
-rw-r--r-- 1 bobcook sf 664 Sep 6 11:42 prog
$ chmod a+x prog
$ chmod g+w groupfile
$ chmod go-xr privatedir
$ ls -lg
total 12
-rw-rw-r-- 1 bobcook sf 2847 Sep 6 11:42 groupfile
drwx------ 2 bobcook sf 32 Sep 6 11:41 privatedir/
-rwxr-xr-x 1 bobcook sf 664 Sep 6 11:42 prog*
$