Next: System Statistics
Up: Powerful Little Programs
Previous: The Power of Unix
In addition to the commands like cd, mv, and rm you
learned in Chapter , there are other commands that
just operate on files but not the data in them. These include
touch, chmod, du, and df. All of these files
don't care what is in the file--the merely change some of the
things Unix remembers about the file.
Some of the things these commands manipulate:
- The time stamptime stamp. Each file has three dates
associated with it.
The three dates
are the creation time (when the file was created), the last
modification time (when the file was last changed), and the last
access time (when the file was last read). - The owner. Every file in Unix is owned by one user or the
other.
- The group. Every file also has a group of users it is
associated with. The most common group for user files is called
users, which is usually shared by all the user account on the
system.
- The permissions . Every file has permissions
(sometimes called ``privileges'') associated with it
which tell Unix who can access what file, or change it, or, in the
case of programs, execute it. Each of these permissions can be
toggled seperately for the owner, the group, and all other users.
touch file1 file2 ...fileN
touch will update the time stamps of the files listed on the
command line to the current time. If a file doesn't exist, touch
will create it. It is also possible to specify the time that
touch will set files to--consult the the manpage for touch.
chmod [-Rfv] mode file1 file2 ...fileN
The command used to change the permissions
on a file is called chmod, short for change mode.
Before I go into how to use the command, let's discuss what
permissions are in Unix. Each file has a group of permissions
associated with it. These permissions tell Unix whether or not the
file can be read from, written to, or executed as a program. (In the
next few paragraphs, I'll talk about users doing these things.
Naturally, any programs a user runs are allowed to do the same things
a user is. This can be a security problem if you don't know what a
particular program does.)
However, Unix recognizes three different people: first, the owner of
the file (and the person allowed to use chmod on that file). The
group of most of your files might be ``users'', meaning the normal
users of the system. (To find out the group of a particular file, use
ls -l file.) Then, there's everybody else who isn't the
owner and isn't a member of the group.
So, a file could have read and write permissions for the owner, read
permissions for the group, and no permissions for all others. Or, for
some reason, a file could have read/write permissions for the group
and others, but no permissions for the owner!
Let's try using chmod to change a few permissions. First, create
a new file using cat, emacs, or any other program. By
default, you'll be able to read and write this file. (The permissions
given other people will vary depending on how the system and your
account is setup.) Make sure you can read the file using
cat. Now, let's take away your read privilege by using chmod
u-r filename. (The parameter u-r decodes to ``user
minus read''.) Now if you try to read the file, you get a
Permission denied error! Add read privileges back by using
chmod u+r filename.
Directory permissions use the same three
ideas: read, write, and execute, but act slightly differently. The
read privilege allows the user (or group or others) to read the
directory--list the names of the files. The write permission allows
the user (or group or others) to add or remove files. The execute
permission allows the user to access files in the directory or any
subdirectories. (If a user doesn't have execute permissions for a
directory, they can't even cd to it!)
To use chmod, replace the mode with what to operate on,
either user, group, other, or all, and what to
do with them. (That is, use a plus sign to indicate adding a privilege
or a minus sign to indicate taking one away. Or, an equals sign will
specify the exact permissions.) The possible permissions to add are
read, write, and execute.
chmod's R flag will change a directory's permissions, and
all files in that directory, and all subdirecties, all the way down
the line. (The `R' stands for recursive.) The f flag forces
chmod to attempt to change permissions, even if the user isn't
the owner of the file. (If chmod is given the f flag, it
won't print an error message when it fails to change a file's
permissions.) The v flag makes chmod verbose--it will
report on what it's done.
Next: System Statistics
Up: Powerful Little Programs
Previous: The Power of Unix
Converted on:
Mon Apr 1 08:59:56 EST 1996
|