Navigating the Linux File System
◾
101
If you want to change
a permission on all three of u, g, and o, you can use ‘a’ instead for
all.
For instance, given the original permissions, we want to add execute to everyone. This
could be done with
chmod a
+
x file1.txt
The second approach to altering permissions uses an
=
instead of
+
or –. In
this case,
you assign new permissions rather than a change to the permissions. For instance, if you
want to make file1.txt readable, writable, and executable to the user, readable to the group,
and nothing to the world, this could be done with
chmod u=rwx,g=r,o= file1.txt
In this case, since we want other to have no access, we place no letters after the o
=
. You
can omit u
=
, g
=
, or o
=
if no change is taking place to that particular party.
Additionally, you can combine
=
,
+
, and
−
as in
chmod u
=
rwx,g
–
w,o
–
r file1.txt
You can make multiple changes by combining
+
and
−
to any of u, g, and o, as in
chmod u
=
rwx,g
–
w
+
x,o
–
r file1.txt
The final approach is similar to the
=
approach in that you
are changing all of the per-
missions. In this approach, you replace the letters with a 3-digit number. Each digit is the
summation of the access rights granted to that party (user, group, other) where readability
is a 4, writability is a 2, and executability is a 1.
Readability, writability, and executability would be 4
+
2
+
1
=
7. Readability and exe-
cutability would be 4
+
1
=
5. No access at all would be 0. Let us assume that we want file1.
txt to have readable, writable, and executable access for the owner, readable, and executable
access for the group and no access for the world. The command would be
chmod 750 file1.txt
Another way to think of each digit is as a binary number. Assume that a 1
bit means
“access” and a 0 bit means “no access.” The readability bit comes first followed by the writ-
ability bit followed by the executability bit, or rwx. To provide rwx, this would be 111
which is binary for 7 (4
+
2
+
1). For rw- (i.e., readable and writable but not executable), this
would be 110
=
6 (4
+
2). For r-x (readable and executable), this would be 101
=
5 (4
+
1).
For r-- (read only), this would be 100
=
4.
The combinations rwx, rw-, r-x, r-- might look familiar to you, as well they should.
When you do a long listing (
ls -l
), the first 10 characters of a line are a combination
of letters and hyphens. The first letter denotes the type of file (as
we discussed in the find
102
◾
Linux with Operating System Concepts
command). The remaining nine characters denote the permissions. For instance,
rwxr-
xr--
means that the user has read, write, and execute access, the group has read and exe-
cute access and other has only read access. Figure 3.6 illustrates the grouping of these first
10 characters. The leading hyphen indicates the file is a regular file (whereas a ‘d’ would
refer to a directory and an ‘l’
means a symbolic link; we discuss the other types in Chapter
10). Here, we see a file whose access rights are rwxr-x--x which makes it readable, writable,
and executable by user, readable and executable by group and executable by world. The
three-digit value for this item is 751.
While you are free to use any of the three combinations for chmod, the 3-digit approach
is the least amount of typing. But it does require learning the possible values. See Table 3.8
File type
(- means
regular file)
u permissions
g permissions
o permissions
- rwx r-x --x
FIGURE 3.6
Reading permissions.
TABLE 3.8
Example 3-Digit Permissions
Do'stlaringiz bilan baham: