| |
FilesFiles are the vehicles for storage of data and programs on a long- term basis. Your Unix files are stored on a magnetic disk, from which you may easily retrieve them to work with. All of your files are referenced by names which you choose and assign to them. Creating FilesFiles are created through use of a text editor, which is a special utility program designed to assist you in entering text and in making changes and updates to text you have already entered. The two most commonly-used Unix editors are vi and emacs; there is also a newer and easier-to-use editor on-line--- pico. Naming FilesUnix allows file names of up to 256 characters in length, including any printable characters except the forward slash. It is best, however, to avoid characters such as the semicolon, the ampersand, the asterisk, and so on, because these can conflict with certain Unix commands. Most users choose from the alphanumeric characters, the period and the underscore. A period in a file name has no special significance, as Unix does not require file types or extensions, although language compilers will use them. Some Unix file names begin with a period. These are known as "hidden" files because their names are not usually displayed when you enter the command for a listing of your files. Hidden files are used to define various startup parameters, and allow you considerable leeway in customizing your environment. Remember that Unix is a case-sensitive system---a file named junk is not the same as one named Junk from Unix's viewpoint. Be consistent in your usage. Some Commands for Manipulating Files
It is important to remember that Unix does not maintain various versions of the same file; the old file is automatically overwritten by the new. If you want to retain old versions, use the cp command to store your file under a different name. For extra security you can invoke noclobber to guard against accidental overwriting:
Using WildcardsUnix provides the ability to refer to multiple files in one command through the use of "wildcards." The asterisk (*) matches any number of characters in a file name, while the question mark ( ?) matches only a single character. To illustrate:
DirectoriesStructureUnder Unix, files are organized hierarchically in what is called a tree structure, stemming from the root at the system level. They are stored in directories, which are simply special-purpose files, referred to in the same manner as any other files. The files grouped within a directory file can also contain the names of other directory files, often called subdirectories. These subdirectories can in turn have their own subdirectories, and so on. All directory and subdirectory files on a Unix system are actually subdirectories of the root directory, which is designated by the forward slash character alone. Directory files reference locations and links to other files; they are in binary format and are not printable or displayable. Office of Information Technology has configured the file system so that like users are grouped under the same subdirectory. One of the files in UMBC7's root directory is the subdirectory sd. Stemming from this is staffguest, which includes, as you might imagine, further subdirectories staff and guest. Hypothetical user Ted, who belongs to the staff group, has a subdirectory created within staff named ted. Graduate student and faculty accounts have a similar logical structure stemming from /umbc. The student-use systems employ a similar scheme but with differing directory names. The highest directory level assigned to a given user is also known as the HOME directory, and is the one to which the user is given immediate access upon login. If the user takes no action to change directories, it is the only one he or she will use. Therefore, in the absence of any commands to manipulate the directory level, all files will be written to the HOME directory. Given this, HOME is frequently referred to as the login default directory. Many users, however, create large numbers of files. They often find that organizing their files logically in separate subdirectories makes finding and working with them much simpler. Unix imposes no limits on the depth of its directory structure, so that individual sites and users may organize their files to their own liking. As is noted above, the root directory is represented by a single forward slash character. Subsequent forward slashes used in depicting file locations symbolize subdirectories of the previous subdirectory. Directory file names are the routes to specific files and are known as path names. A path name starting with a slash begins at the root directory and is called an absolute path name. When a path name begins at the current directory, it is a relative path name. A file named without reference to a directory is understood to reside in the current directory. Thus ls /umbc/grad/jsnow3/programs and ls will obtain the same listing if programs is the current working directory. Similarly if /umbc/grad/jsnow3/programs is the current directory, the designation lisp/data means a file called data in a lower directory called lisp, or /umbc/grad/jsnow3/programs/lisp/data Every directory contains a file called . (dot) and another file called .. (dot-dot). These are invisible files, because they represent merely links to directories. Dot refers to the current directory, and therefore is a link to itself. Dot-dot is the directory's link to its parent directory, one level higher. By specifying a path name using dot-dot you can backtrack and move into another branch of the tree structure. For example, if the current directory is /umbc/faculty/smith/programs, then ../games refers to another directory, games, stemming from smith or to a text file named games located in the smith directory. The single dot directory reference can be used as a shorthand symbol. If you wanted to copy a file called file1 from /umbc/faculty/smith to your current directory, which happens to be /umbc/faculty/smith/programs, you could use the command form cp /umbc/student/ted/file1 . with the single dot representing your current directory. Dot and dot-dot are examples of "hidden" files---files whose names begin with a period. Some Commands to Manipulate Directories
A note About Directory PointersYou should note that Unix's rm command does not necessarily delete a given file or files---what it does is to remove the file's directory pointer or link, so that from the viewpoint of the user executing the command the file has been deleted. However, many users may have access to the same file. This does not mean that a copy of the file is created for each user who has access; in fact, the file resides physically in only one place on the system and individual users' directories contain links to the file, not the file itself. ln /umbc/grad/ted/data /umbc/faculty/smith Links file data to the smith directory. There are now two paths for the one file, as two separate directories have pointers or links to data. The file will continue to exist as long as there is at least one link to a user. When that last link is severed by rm, Unix erases the file. File PermissionsUnder Unix there are three categories of potential file users: user, group and other, to which three types of file access can be given: read, write and execute. (Delete access is determined by write access to the directory containing the file.) By default, accounts are set up so that only the owner of a file may have access to it. The chmod command can be used to change this protection.
The system will respond with a line of information about each file, including a file permission code. A code such as -rwxr-x--x is interpreted as follows: The leading minus sign (-) means that the file is a standard one and not a directory, which has the code d. The file's user or owner has read, write and execute permission ( rwx); the owner's group has read and execute access ( r-x); and others may execute this file only ( --x). Execute access, it should be noted, is applicable for files containing programs that can be run or executed. Assuming that the command ls -l is entered while the user is in a directory containing the two files .cshrc and .emacs, the output might be:
The first column of ten characters sets out the permissions on the file as described above. The second column, containing the number "1," lists the number of links that the file has. Next is the username of the file's owner. Column four lists the size of the file in bytes. For files containing textual information a byte is synonymous with a character. The fifth column shows the date and time of the last file modification, and the last column displays the name of the file. GL/AFS Users: Under AFS, the traditional chmod commands are not relevant. Instead, AFS has a sophisticated access control list (ACL) mechanism. Through an ACL you have granular control of who can access you files. As you might expect, since an ACL is much more powerful there are some additional options that you need to consider when using ACL's. The AFS documentation has a section on Protecting Your Files and Directories that you can read.
UMBC7 On UMBC7 the command to check your disk quota is the command quota. The quota command is used to list your current disk usage and the maximum amount you are allocated. While the quota command will give you the total amount of space used but it doesn't give any information as to what directories are using the most space or what files within a directory are the largest. In order to manage your disk space these are two necessary pieces of information. Luckily, there are commands on UNIX for doing this. The command du provides a summary of the disk usage by directory in your account. The command ls will list the size of ech file. Finally, we have created a hybrid command using a combination of commands to give you a quick update on where your file space is being used.
GL/AFS On GL, or when using the UMBC AFS file services, the command to check your disk quota is the AFS command fs listquota (listquota can be abbreviated as lq) . The fs listquota command can be used to list your current disk usage and quota . The fs lq command will give you the total amount of space used but like the traditional quota command, it doesn't give any information as to what directories are using the most space or what files within a directory are the largest. In order to manage your disk space these are two necessary pieces of information. Luckily, there are commands for doing this. The command du provides a summary of the disk usage by directory in your account. The command ls will list the size of ech file. Finally, we have created a hybrid command using a combination of commands to give you a quick update on where your file space is being used.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||