Free Hosting Online for WorkStations

< Previous | Contents | Next >

Reading, Writing, And Executing

Access rights to files and directories are defined in terms of read access, write access, and execution access. If we look at the output of the ls command, we can get some clue as to how this is implemented:



[me@linuxbox ~]$ > foo.txt

[me@linuxbox ~]$ ls -l foo.txt

-rw-rw-r-- 1 me me 0 2016-03-06 14:52 foo.txt

[me@linuxbox ~]$ > foo.txt

[me@linuxbox ~]$ ls -l foo.txt

-rw-rw-r-- 1 me me 0 2016-03-06 14:52 foo.txt


The first ten characters of the listing are the file attributes. The first of these characters is the file type. Here are the file types you are most likely to see (there are other, less com - mon types too):


Table 9-1: File Types


Attribute File Type

Attribute File Type

- A regular file.


d A directory.


l A symbolic link. Notice that with symbolic links, the remaining file attributes are always “rwxrwxrwx” and are dummy values. The real file attributes are those of the file the symbolic link points to.



c A character special file. This file type refers to a device that handles data as a stream of bytes, such as a terminal or modem.


b A block special file. This file type refers to a device that handles data in blocks, such as a hard drive or CD-ROM drive.



The remaining nine characters of the file attributes, called the file mode, represent the read, write, and execute permissions for the file's owner, the file's group owner, and everybody else:


Owner

Group

World

rwx

rwx

rwx


When set, the r, w, and x mode attributes have the following effect on files and directo- ries:


Table 9-2: Permission Attributes


Attribute Files Directories

Attribute Files Directories

r Allows a file to be opened and read.


w Allows a file to be written to or truncated, however this attribute does not allow files to be renamed or deleted. The ability to delete or rename files is determined by directory attributes.

x Allows a file to be treated as a program and executed. Program files written in scripting languages must also be set as readable to be executed.

Allows a directory's contents to be listed if the execute attribute is also set.

Allows files within a directory to be created, deleted, and renamed if the execute attribute is also set.


Allows a directory to be entered, e.g., cd directory.



Here are some examples of file attribute settings:


Table 9-3: Permission Attribute Examples


File Attributes Meaning

File Attributes Meaning

-rwx------ A regular file that is readable, writable, and executable by the file's owner. No one else has any access.


-rw------- A regular file that is readable and writable by the file's owner.

No one else has any access.


-rw-r--r-- A regular file that is readable and writable by the file's owner. Members of the file's owner group may read the file. The file is world-readable.


-rwxr-xr-x A regular file that is readable, writable, and executable by the file's owner. The file may be read and executed by everybody else.


-rw-rw---- A regular file that is readable and writable by the file's owner and members of the file's group owner only.


lrwxrwxrwx A symbolic link. All symbolic links have “dummy”

permissions. The real permissions are kept with the actual file pointed to by the symbolic link.


drwxrwx--- A directory. The owner and the members of the owner group may enter the directory and, create, rename and remove files within the directory.


drwxr-x--- A directory. The owner may enter the directory and create, rename and delete files within the directory. Members of the owner group may enter the directory but cannot create, delete or rename files.



 

Top OS Cloud Computing at OnWorks: