• No results found

Structure of the file system

In document Unix (Page 148-155)

System administration

5.10 Structure of the file system

The UNIX file system is organised as a hierarchy of directories starting from a single directory called root which is represented by a / (slash). Imagine it as being similar to the root system of a plant or as an inverted tree structure.

Immediately below the root directory are several system directories that contain information required by the operating system. The file holding the UNIX kernel is also here.

The standard system directories are shown below. Each one contains specific types of file. The details may vary between different UNIX systems, but these directories should be common to all. Select one for more information on it.

/(root) |

--- | | | | | | | |

/bin /dev /etc /home /lib /tmp /usr kernel file

• Home directory

Any UNIX system can have many users on it at any one time. As a user you are given a home directory in which you are placed whenever you log on to the system.

User's home directories are usually grouped together under a system directory such as /home. A large UNIX system may have several hundred users, with their home directories grouped in subdirectories according to some schema such as their organizational department.

• Pathnames

Every file and directory in the file system can be identified by a complete list of the names of the directories that are on the route from the root directory to that file or directory.

Each directory name on the route is separated by a / (forward slash). For example:

/usr/local/bin/ue

This gives the full pathname starting at the root directory and going down through the directories usr, local and bin to the file ue - the program for the MicroEMACS editor.

You can picture the full pathname as looking like this: /(root) | | --- | | tmp usr | --- ... ---- | | |

/games /local /spool | --- | /bin | --- | ue • Relative pathnames

You can define a file or directory by its location in relation to your current directory. The pathname is given as / (slash) separated list of the directories on the route to the file (or directory) from your current directory.

A .. (dot dot) is used to represent the directory immediately above the current directory.

In all shells except the Bourne shell, the ~ (tilde) character can be used as shorthand for the full pathname to your home directory.

5.11 Controlling access to your files and directories

Every file and directory in your account can be protected from or made accessible to other users by changing its access permissions.

You can only change the permissions for files and directories that you own.

• Displaying access permissions

To display the access permissions of a file or directory use the the command:

ls -l filename (directory)

This displays a one line summary for each file or directory. For example:

-rwxr-xr-x 1 erpl08 staff 3649 Feb 22 15:51 my.html

This first item -rwxr-xr-x represents the access permissions on this file. The following items represent the number of links to it; the username of the person owning it; the name of the group which owns it; its size; the time and date it was last changed, and finally, its name.

• Understanding access permissions

There are three types of permissions:

w write to the file or directory

x execute the file or search the directory

Each of these permissions can be set for any one of three types of user:

u the user who owns the file (usually you)

g members of the group to which the owner belongs o all other users

The access permissions for all three types of user can be given as a string of nine characters:

user group others r w x r w x r w x

These permissions have different meanings for files and directories.

Summary of access permissions Permission File Directory

r read read a file list files in ...

w write write a file create file in ... rename file in ... delete file ...

x execute execute a read a file in ... shell script write to a file in ...

execute a file in ...

execute a shell script in ...

• Default access permissions

When you create a file or directory its access permissions are set to a default value. These are usually:

rw---

gives you read and write permission for your files; no access permissions for the group or others.

rwx---

gives you read write and execute permission for your directories; no access permissions for the group or others.

Access permissions for your home directory are usually set to rwx--x--x or rwxr-xr-x.

• Changing the group ownership of files

Every user is a member of one or more groups. To find out which groups you belong to use the command:

groups

To find out which groups another user belongs to use the command:

groups username

Your files and directories are owned by the group (or one of the groups) that you belong to. This is known as their "group ownership".

ls -gl

You can change the group ownership of a file or directory with the command:

chgrp group_name file/directory_name

You must be a member of the group to which you are changing ownership to.

• Changing access permissions

To change the access permissions for a file or directory use the command

chmod mode filename

chmod mode directory_name

The "mode" consists of three parts: who the permissions apply to, how the permissions are set and which permissions to set.

Who means

This is specified as one of:

u (user) the owner of the file

g (group) the group to which the owner belongs o (other) everyone else

a (all) u, g and o (the world)

How means

This is given as one of:

- subtract the specified permission

= assign the specified permission, ignoring whatever may have been set before. Which means

These are specified by one or more from:

r read w write x execute

Remember that these permissions have different meanings for files and directories.

In document Unix (Page 148-155)

Related documents