Go to the first, previous, next, last section, table of contents.


Other Information about Files

This section describes the functions for getting detailed information about a file, other than its contents. This information includes the mode bits that control access permission, the owner and group numbers, the number of names, the inode number, the size, and the times of access and modification.

Function: file-modes filename
This function returns the mode bits of filename, as an integer. The mode bits are also called the file permissions, and they specify access control in the usual Unix fashion. If the low-order bit is 1, then the file is executable by all users, if the second-lowest-order bit is 1, then the file is writable by all users, etc.

The highest value returnable is 4095 (7777 octal), meaning that everyone has read, write, and execute permission, that the SUID bit is set for both others and group, and that the sticky bit is set.

(file-modes "~/junk/diffs")
     => 492               ; Decimal integer.
(format "%o" 492)
     => "754"             ; Convert to octal.

(set-file-modes "~/junk/diffs" 438)
     => nil

(format "%o" 438)
     => "666"             ; Convert to octal.

% ls -l diffs
  -rw-rw-rw-  1 lewis 0 3063 Oct 30 16:00 diffs

Function: file-nlinks filename
This functions returns the number of names (i.e., hard links) that file filename has. If the file does not exist, then this function returns nil. Note that symbolic links have no effect on this function, because they are not considered to be names of the files they link to.

% ls -l foo*
-rw-rw-rw-  2 rms       4 Aug 19 01:27 foo
-rw-rw-rw-  2 rms       4 Aug 19 01:27 foo1

(file-nlinks "foo")
     => 2
(file-nlinks "doesnt-exist")
     => nil

Function: file-attributes filename
This function returns a list of attributes of file filename. If the specified file cannot be opened, it returns nil.

The elements of the list, in order, are:

  1. t for a directory, a string for a symbolic link (the name linked to), or nil for a text file.
  2. The number of names the file has. Alternate names, also known as hard links, can be created by using the add-name-to-file function (see section Changing File Names and Attributes).
  3. The file's UID.
  4. The file's GID.
  5. The time of last access, as a list of two integers. The first integer has the high-order 16 bits of time, the second has the low 16 bits. (This is similar to the value of current-time; see section Time of Day.)
  6. The time of last modification as a list of two integers (as above).
  7. The time of last status change as a list of two integers (as above).
  8. The size of the file in bytes.
  9. The file's modes, as a string of ten letters or dashes, as in `ls -l'.
  10. t if the file's GID would change if file were deleted and recreated; nil otherwise.
  11. The file's inode number. If possible, this is an integer. If the inode number is too large to be represented as an integer in Emacs Lisp, then the value has the form (high . low), where low holds the low 16 bits.
  12. The file system number of the file system that the file is in. This element and the file's inode number together give enough information to distinguish any two files on the system--no two files can have the same values for both of these numbers.

For example, here are the file attributes for `files.texi':

(file-attributes "files.texi")
     =>  (nil 1 2235 75 
          (8489 20284) 
          (8489 20284) 
          (8489 20285)
          14906 "-rw-rw-rw-" 
          nil 129500 -32252)

and here is how the result is interpreted:

nil
is neither a directory nor a symbolic link.
1
has only one name (the name `files.texi' in the current default directory).
2235
is owned by the user with UID 2235.
75
is in the group with GID 75.
(8489 20284)
was last accessed on Aug 19 00:09.
(8489 20284)
was last modified on Aug 19 00:09.
(8489 20285)
last had its inode changed on Aug 19 00:09.
14906
is 14906 characters long.
"-rw-rw-rw-"
has a mode of read and write access for the owner, group, and world.
nil
would retain the same GID if it were recreated.
129500
has an inode number of 129500.
-32252
is on file system number -32252.


Go to the first, previous, next, last section, table of contents.