UNIX System Administration Handbook - Evi Nemeth [52]
The next field is the size of the file in bytes. This file is 85,924 bytes long, almost 84K.6 Next comes the date of last modification: September 27, 1997. The last field in the listing is the name of the file, /bin/sh.
ls output is slightly different for a device file. For example:
% ls -l /dev/ttya
crw-rw-rw- 1 root daemon 12, 0 Dec 20 1998 /dev/ttya
Most fields are the same, but instead of a size in bytes, the major and minor device numbers are shown. /dev/ttya is the first unit controlled by device driver 12 (on this system, the terminal driver).
One ls option that’s useful for scoping out hard links is -i, which makes ls show each file’s “inode number.” Without going into too much detail about the implementation of the filesystem, we’ll just say that the inode number is an index into a table that enumerates all the files in the filesystem. Inodes are the “things” that are pointed to by directory entries; entries that are hard links to the same file will have the same inode number. To figure out a complex web of links, you’ll need ls -l to show link counts, ls -i to show inode numbers, and ls -R to list files recursively. Of course, you can use these options together in any combination.
The system keeps track of modification timestamps, link counts, and file size information automatically. Conversely, the permission bits, ownership, and group ownership change only when they are specifically altered with the chmod, chown, and chgrp commands.
FreeBSD bonus flags
FreeBSD and other 4.4BSD-based systems define a variety of “bonus” flags that can be set on files. These flags generally invoke additional filesystem semantics. For example, the sappnd flag makes a file append-only (useful for log files) and the schg flag makes it immutable and undeletable. Use ls -lo to see the flags attached to a file:
% ls -lo /kernel
-r-xr-xr-x 1 root wheel schg 2498230 Nov 30 23:51 /kernel
Use the chflags command to change them:
# chflags noschg /kernel
# ls -lo /kernel
-r-xr-xr-x 1 root wheel - 2498230 Nov 30 23:51 /kernel
See the chflags(1) man page for a list of the available flags.
chmod: change permissions
The chmod command changes the permissions on a file. Only the owner of the file and the superuser can change its permissions. To use the command on early UNIX systems, you had to learn a bit of binary or octal notation, but current versions accept either octal notation or a more cryptic mnemonic syntax. The octal syntax is generally more convenient for system administrators, but it can only be used to specify an absolute value for the permission bits. The mnemonic syntax can modify some bits while leaving others alone.
The first argument to chmod is a specification of the permissions to be assigned, and the second and subsequent arguments are names of files on which permissions should be changed. In the octal case, the first octal digit of the specification is for the owner, the second is for the group, and the third is for everyone else. If you want to turn on the setuid, setgid, or sticky bits, you use four octal digits rather than three, with the three special bits forming the first digit.
Table 5.3 illustrates the eight possible combinations for each set of three bits, where r, w, and x stand for read, write, and execute.
Table 5.3 Permission encoding for chmod
For example, chmod 711 myprog gives all permissions to the owner and execute-only permission to everyone else.7
The full details of chmod’s mnemonic syntax can be found in the chmod man page. Some examples of mnemonic specifications are shown in Table 5.4.
Table 5.4 Examples of chmod’s mnemonic syntax
The hard part about using the mnemonic