GNU file utilities - 8. Changing file attributes

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

# 8. Changing file attributes

A file is not merely its contents, a name, and a file type (see section 7. Special file types). A file also has an owner (a userid), a group (a group id), permissions (what the owner can do with the file, what people in the group can do, and what everyone else can do), various timestamps, and other information. Collectively, we call these a file's attributes.

These commands change file attributes.

## 8.1 `chown`: Change file owner and group

`chown` changes the user and/or group ownership of each given file to new-owner or to the user and group of an existing reference file. Synopsis:

    chown [option]... {new-owner | --reference=file} file...

If used, new-owner specifies the new owner and/or group as follows (with no embedded white space):

    [owner] [ [:.] [group] ]

Specifically:

owner
  If only an owner (a user name or numeric user id) is given, that user is made the owner of each given file, and the files' group is not changed.
owner``.'`group
owner``:'`group
  If the owner is followed by a colon or dot and a group (a group name or numeric group id), with no spaces between them, the group ownership of the files is changed as well (to group).
owner``.'`
owner``:'`
  If a colon or dot but no group name follows owner, that user is made the owner of the files and the group of the files is changed to owner's login group.
``.'`group
``:'`group
  If the colon or dot and following group are given, but the owner is omitted, only the group of the files is changed; in this case, `chown` performs the same function as `chgrp`.

The program accepts the following options. Also see section 2. Common options.

``-c'`
``--changes'`
  Verbosely describe the action for each file whose ownership actually changes.
``-f'`
``--silent'`
``--quiet'`
  Do not print error messages about files whose ownership cannot be changed.
``--dereference'`
  Do not act on symbolic links themselves but rather on what they point to.
``-h'`
``--no-dereference'`
  Act on symbolic links themselves instead of what they point to. This is the default. This mode relies on the `lchown` system call. On systems that do not provide the `lchown` system call, `chown` fails when a file specified on the command line is a symbolic link. By default, no diagnostic is issued for symbolic links encountered during a recursive traversal, but see ``--verbose'`.
``--reference=file'`
  Use the user and group of the reference file instead of an explicit new-owner value.
``-v'`
``--verbose'`
  Verbosely describe the action (or non-action) taken for every file. If a symbolic link is encountered during a recursive traversal on a system without the `lchown` system call, and ``--no-dereference'` is in effect, then issue a diagnostic saying neither the symbolic link nor its referent is being changed.
``-R'`
``--recursive'`
  Recursively change ownership of directories and their contents.

## 8.2 `chgrp`: Change group ownership

`chgrp` changes the group ownership of each given file to group (which can be either a group name or a numeric group id) or to the group of an existing reference file. Synopsis:

    chgrp [option]... {group | --reference=file} file...

The program accepts the following options. Also see section 2. Common options.

``-c'`
``--changes'`
  Verbosely describe the action for each file whose group actually changes.
``-f'`
``--silent'`
``--quiet'`
  Do not print error messages about files whose group cannot be changed.
``-f'`
``--no-dereference'`
  Act on symbolic links themselves instead of what they point to. Only available if the `lchown` system call is provided.
``--reference=file'`
  Use the group of the reference file instead of an explicit GROUP.
``-v'`
``--verbose'`
  Verbosely describe the action or non-action taken for every file.
``-R'`
``--recursive'`
  Recursively change the group ownership of directories and their contents.

## 8.3 `chmod`: Change access permissions

`chmod` changes the access permissions of the named files. Synopsis:

    chmod [option]... {mode | --reference=file} file...

`chmod` never changes the permissions of symbolic links, since the `chmod` system call cannot change their permissions. This is not a problem since the permissions of symbolic links are never used. However, for each symbolic link listed on the command line, `chmod` changes the permissions of the pointed-to file. In contrast, `chmod` ignores symbolic links encountered during recursive directory traversals.

If used, mode specifies the new permissions. For details, see the section on section 3. File permissions.

The program accepts the following options. Also see section 2. Common options.

``-c'`
``--changes'`
  Verbosely describe the action for each file whose permissions actually changes.
``-f'`
``--silent'`
``--quiet'`
  Do not print error messages about files whose permissions cannot be changed.
``-v'`
``--verbose'`
  Verbosely describe the action or non-action taken for every file.
``--reference=file'`
  Use the mode of the reference file instead of an explicit MODE. See section 3. File permissions.
``-R'`
``--recursive'`
  Recursively change permissions of directories and their contents.

## 8.4 `touch`: Change file timestamps

`touch` changes the access and/or modification times of the specified files. Synopsis:

    touch [option]... file...

If the first file would be a valid argument to the ``-t'` option and no timestamp is given with any of the ``-d'`, ``-r'`, or ``-t'` options and the ``--'` argument is not given, that argument is interpreted as the time for the other files instead of as a file name.

Any file that does not exist is created empty.

If changing both the access and modification times to the current time, `touch` can change the timestamps for files that the user running it does not own but has write permission for. Otherwise, the user must own the files.

The program accepts the following options. Also see section 2. Common options.

``-a'`
``--time=atime'`
``--time=access'`
``--time=use'`
  Change the access time only.
``-c'`
``--no-create'`
  Do not create files that do not exist.
``-d'`
``--date=time'`
  Use time instead of the current time. It can contain month names, timezones, ``am'` and ``pm'`, etc. See section 4. Date input formats.
``-f'`
  Ignored; for compatibility with BSD versions of `touch`.
``-m'`
``--time=mtime'`
``--time=modify'`
  Change the modification time only.
``-r file'`
``--reference=file'`
  Use the times of the reference file instead of the current time.
``-t [[CC]YY]MMDDhhmm[.ss]'`
  Use the argument (optional four-digit or two-digit years, months, days, hours, minutes, optional seconds) instead of the current time. If the year is specified with with only two digits, then CC is 20 for years in the range 0 ... 68, and 19 for year in 69 ... 99. If no digits of the year are specified, the argument is interpreted as a date in the current year.

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