The nine bits assigned to each file for permissions define the access that you and others have to
your file. Permission bits for a regular file appear as
-rwxrwxrwx
.
For a regular file, a dash appears in front of the nine-bit permissions indicator. Instead
of a dash, you might see a d (for a directory), l (for a link), b (for a character device),
or c (for a character device).
Of the nine-bit permissions, the first three bits apply to the owner's permission, the next three
apply to the group assigned to the file, and the last three apply to all others. The
r
stands for read,
the
w
stands for write, and the
x
stands for execute permissions. If a dash appears instead of the
letter, it means that permission is turned off for that associated read, write, or execute.
Because files and directories are different types of elements, read, write, and execute permissions on
files and directories mean different things. Table 2-9 explains what you can do with each of them.
TABLE 2-9
Setting Read, Write, and Execute Permissions
Permission
File
Directory
Read
View what's in the file.
See what files and subdirectories it contains.
Write
Add files or subdirectories to the directory.
Execute
Run the file as a program.
Change to that directory as the current directory,
search through the directory, or execute a program
from the directory.
You can see the permission for any file or directory by typing the
ls -ld
command. The named
file or directory appears as those shown in this example:
$ ls -ld ch3 test
-rw-rw-r-- 1 chris sales 4983 Jan 18 22:13 ch3
drwxr-xr-x 2 chris sales 1024 Jan 24 13:47 test
The first line shows that the
ch3
file has read and write permission for the owner and the group.
All other users have read permission, which means they can view the file but cannot change its
contents or remove it. The second line shows the
test
directory (indicated by the letter
d
before
the permission bits). The owner has read, write, and execute permission, while the group and
other users have only read and execute permissions. As a result, the owner can add, change, or
delete files in that directory, and everyone else can only read the contents, change to that directory,
and list the contents of the directory.
If you own a file, you can use the
chmod
command to change the permission on it as you please.
In one method of doing this, each permission (read, write, and execute) is assigned a number --
r=4, w=2, and x=1 -- and you use each set's total number to establish the permission. For example,
to make permissions wide open for yourself as owner, you'd set the first number to 7 (4+2+1), and
Change the file's content, rename
it, or delete it.
NOTE
NOTE
72
Linux First Steps
Part I