UNIX File Attributes


Case Sensitivity

In UNIX, nearly everything is case-sensitive, including file names and commands. For example, MYFILE, Myfile, and myfile name three distinct and separate files; and the commands a and A could execute entirely different operations. In some cases, UNIX is space-sensitive as well, so a mis-typed case or space can produce unintended results.

Files and directories

Another important concept in UNIX is its hierarchical file system, in which directories are designated by a forward slash (/). For example, /usr/mail/ designates a directory called "mail" within the directory called "usr". Notice that this is similar to how directories and files are organized in DOS except that, in DOS, a backslash (\) separates the directories.

A UNIX file name is a string, or series, of characters; it may include special characters (such as !, @, #, and $) and multiple periods as well as alphanumeric characters. The full, or absolute, path name for a file specifies exactly in which directory it is located; e.g., /usr/local/bin/myfile. If your current directory were /usr/local/bin/, the relative path name, myfile, could be used. You can find out what your current directory is with the pwd command.

File Permissions

UNIX files also have a set of file permissions associated with them. This makes it possible for you to share files with others -- everyone on the same computer, or only to a certain group of people -- and you can specify the level of access you want to grant (read, write, execute). Read access allows you to view files but not change them. Write access allows you to change the contents of the file. Execute permission lets you run (execute) the file.

Since directories are special files in UNIX, file permissions apply to directories, too. For directories, read permission allows you to list the files in the directory; write permission allows you to create or remove files in the directory; and execute permission allows you to cd to the directory.

You can list all the files in your current directory so that the file permissions are also displayed. Do this with the ls -l command. When you do, a listing similar to this will be displayed:

drwx------2jdoe1 student 512Jun1912:06 mail
-rwxr--r--1jdoe1student163 May3016:09file1
drwxr-----4jdoe1student512 May3014:24files
-rwxr-xr-x1jdoe1student321 May3014:36script

Each of these lines describe one file. Reading this output from left to right, the first set of letters and hyphens specify the permissions, then the number of links, owner (jdoe1 in this example), group owner (student), size in bytes, date and time of the last modification, and the file name.

Looking at the permissions, (the first 10 characters of letters and hyphens), the first character of the permissions tells what kind of file it is: d for directory, or hyphen (-) for an ordinary file. Looking at our example, mail and files are directories and the other two are files.

The remaining nine characters are three triplets that give the read, write, and execute permissions. The first triplet gives the permissions for the owner (jdoe1 in our example). The second triplet specifies the permissions for the group (student in our example). The last triplet displays the permissions for the public.

The letter r means read permission, w means write, and x execute. A hyphen (-) indicates the absence of that permission, i.e., that the permission is NOT granted. In the our example, mail is a directory to which only jdoe1 has any permissions. The file called file1 has all three permissions set for jdoe1, and anyone in the same group (student) has read access to it, as does the general public. The files directory is open for anyone in the student group to read, but it is not accessible by the public.

Changing File Permissions

To change the file permission on any of the files you own, you can use the chmod command. The command syntax consists of the group/person to which permission is being granted or revoked, and the type of permission being granted or revoked.
The letter u is for the owner, g for the group, and o for others (public).

To change permission on a file or directory, specify the the group, then + or - to indicate whether the permission is to be granted or revoked, then the access type. For example, to grant your group read permission to the files directory, you could enter
chmod g+r files. Or, to remove public executable access to script, you could enter
chmod o-x script

For more information on file attributes and permissions, see the man page by typing man chmod.