chmod Command
We use the chmod command to change the access mode of a file. This command comes in many flavors, but we'll be talking primarily about one of them.
chmod who=permissions filename
This gives “who” the specified permissions for a given filename.
Who The “who” is a list of letters that specifies whom you’re going to be giving permissions to. These may be specified in any order.
Letter Meaning
u The user who owns the file (this means “you.”)
g The group the file belongs to.
o The other users
a all of the above (an abbreviation for ugo)
Permissions Of course, the permissions are the same letters that you see in the directory listing:
r Permission to read the file.
w Permission to write (or delete) the file.
x Permission to execute the file, or, in the case of a directory, search it.
chmod Examples
Let’s change some of the permissions as we discussed a couple of pages ago. Here’s the way our files are now:
-rwxr-xr-x joe acctg archive.sh
-rw-rw-r-- joe acctg orgchart.gif
-rw-rw-r-- joe acctg personnel.txt
-rw-r--r-- joe acctg publicity.html
drwxrwxr-x joe acctg sales
-rw-r----- joe acctg topsecret.inf
-rwxr-xr-x joe acctg wordmatic
First, let’s prevent outsiders from executing archive.sh
Before: -rwxr-xr-x archive.sh
Command: chmod o=r archive.sh
After: -rwxr-xr-- archive.sh
Take away all permissions for the group for topsecret.inf We do this by leaving the permissions part of the command empty.
Before: -rw-r----- topsecret.inf
Command: chmod g= topsecret.inf
After: -rw------- topsecret.inf
Open up publicity.html for reading and writing by anyone.
Before: -rw-r--r-- publicity.html
Command: chmod og=rw publicity.html
After: -rw-rw-rw- publicity.html
|