Next: recurse, Previous: transform, Up: Choosing [Contents][Index]

### 6.8 Operating Only on New Files

The `--after-date=date` (`--newer=date`, `-N date`) option causes `tar` to only work on files whose data modification or status change times are newer than the date given. If date starts with ‘`/`’ or ‘`.`’, it is taken to be a file name; the data modification time of that file is used as the date. If you use this option when creating or appending to an archive, the archive will only include new files. If you use `--after-date` when extracting an archive, `tar` will only extract files newer than the date you specify.

If you only want `tar` to make the date comparison based on modification of the file’s data (rather than status changes), then use the `--newer-mtime=date` option.

You may use these options with any operation. Note that these options differ from the `--update` (`-u`) operation in that they allow you to specify a particular date against which `tar` can compare when deciding whether or not to archive the files.

`--after-date=date`
`--newer=date`
`-N date`

  Only store files newer than date.

  Acts on files only if their data modification or status change times are later than date. Use in conjunction with any operation.

  If date starts with ‘`/`’ or ‘`.`’, it is taken to be a file name; the data modification time of that file is used as the date.

`--newer-mtime=date`

  Acts like `--after-date`, but only looks at data modification times.

These options limit `tar` to operate only on files which have been modified after the date specified. A file’s status is considered to have changed if its contents have been modified, or if its owner, permissions, and so forth, have been changed. (For more information on how to specify a date, see Date input formats; remember that the entire date argument must be quoted if it contains any spaces.)

Gurus would say that `--after-date` tests both the data modification time (`mtime`, the time the contents of the file were last modified) and the status change time (`ctime`, the time the file’s status was last changed: owner, permissions, etc.) fields, while `--newer-mtime` tests only the `mtime` field.

To be precise, `--after-date` checks both `mtime` and `ctime` and processes the file if either one is more recent than date, while `--newer-mtime` only checks `mtime` and disregards `ctime`. Neither does it use `atime` (the last time the contents of the file were looked at).

Date specifiers can have embedded spaces. Because of this, you may need to quote date arguments to keep the shell from parsing them as separate arguments. For example, the following command will add to the archive all the files modified less than two days ago:

    $ tar -cf foo.tar --newer-mtime '2 days ago'

When any of these options is used with the option `--verbose` (see verbose tutorial) GNU `tar` will try to convert the specified date back to its textual representation and compare that with the one given with the option. If the two dates differ, `tar` will print a warning saying what date it will use. This is to help user ensure he is using the right date. For example:

    $ tar -c -f archive.tar --after-date='10 days ago' .
    tar: Option --after-date: Treating date '10 days ago' as 2006-06-11
    13:19:37.232434

> Please Note: `--after-date` and `--newer-mtime` should not be used for incremental backups. See Incremental Dumps, for proper way of creating incremental backups.

Next: recurse, Previous: transform, Up: Choosing [Contents][Index]