[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [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 want tar to make the date comparison based only 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

Act like ‘--after-date’, but look only 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’ checks only mtime and disregards ctime. Neither option uses 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 section The ‘--verbose’ Option) GNU tar converts the specified date back to a textual form and compares that with the one given with the option. If the two forms differ, tar prints both forms in a message, to help the user check that the right date is being used. 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 section Using tar to Perform Incremental Dumps, for proper way of creating incremental backups.


[ << ] [ < ] [ Up ] [ > ] [ >> ]

This document was generated on August 23, 2023 using texi2html 5.0.