# tar - does --newer-* options work?



## Twister (Nov 20, 2012)

Hello!

I try to create tar archive with files newer than specific date. I use --newer-mtime option.
Man says:

```
"The --newer and --newer-mtime switches accept a variety of common date
and time specifications, including ``12 Mar 2005 7:14:29pm'', 
``2005-03-12 19:14'', ``5 minutes ago'', and ``19:14 PST May 1''."
```


But when I use --newer-mtime '2 days ago' - tar creates empty archive.

When I use --newer-mtime '2012-11-19' or --newer-mtime '`date -v -1d`' tar starts to add all files to archive.

Also I've tried "--newer-mtime='2 days ago'", "--newer-mtime='2012-11-19'", "--newer-mtime='`date -v -1d`'"
Result is same - "--newer-mtime" does not work (or works differently...)

Tell me please - what is wrong? Me, my date specification or tar?


----------



## fonz (Nov 20, 2012)

What are the *exact* commands you tried?

Fonz


----------



## Twister (Nov 20, 2012)

```
tar czf /mnt/test.tar.gz --options gzip:3 --one-file-system --newer-mtime "2 days ago" /
tar vvczf /mnt/test.tar.gz --options gzip:3 --one-file-system --newer-mtime "2 days ago" /
tar vvczf /mnt/test.tar.gz --options gzip:3 --one-file-system --newer-mtime-than /tmp/test.test /
tar vvczf /mnt/test.tar.gz --options gzip:3 --one-file-system --newer-mtime-than /tmp/test.test /usr
tar vvczf /mnt/test.tar.gz --options gzip:3 --one-file-system --newer-mtime-than /tmp/test.test /var
tar vvczf /mnt/test.tar.gz --options gzip:3 --one-file-system --newer-mtime-than /tmp/test.test /var/
tar vvczf /mnt/test.tar.gz --options gzip:3 --one-file-system --newer-mtime-than /tmp/test.test /var/
tar vvczf /mnt/test.tar.gz --options gzip:3 --one-file-system --newer-mtime 3 days ago /tmp/test.test /var/
tar vvczf /mnt/test.tar.gz --options gzip:3 --one-file-system --newer-mtime '3 days ago' /tmp/test.test /var/
tar vvczf /mnt/test.tar.gz --options gzip:3 --one-file-system --newer-mtime '3 days ago' /var/
tar vvczf /tmp/test.tar.gz --options gzip:3 --one-file-system --newer-mtime '2012-11-18:00:00:00' /var
```

And so on with many different time specifications.


----------



## fonz (Nov 20, 2012)

Hmm, interesting. The syntax does seem ok to me, but I'm getting the same (incorrect) results as you. I also tried it on a Linux machine (which of course has GNU tar), where it does work as expected. You may have found a bug. If nobody else comes along who knows better, you might want to file a PR.

Fonz

Edit: although they don't fix the original problem there are at least two workarounds you could try: either install archivers/gtar and see if that's any better, or use find(1) in combination with tar(1), e.g. something like (untested, probably needs additional options but you'll get the idea) `# tar cvf archive.tar `find -mmin 2880 /``

Note to add: if you're using this for an incremental backup you might want to use the -p option of tar when extracting (preserves ownership and permissions) if you didn't do that already.


----------

