问题原文
原帖链接 · user374987 · CC BY-SA 3.0
I have this tar command I am trying to run -
tar -N '2016-01-01' -jcvf archive.tar.bz2 /home/myhome
Inside of the home directory, I have the following files that should be filtered
-rwx------. 1 1000 1000 89097 Dec 3 2011 automysqlbackup
-rw-------. 1 1000 1000 11858 Nov 21 2011 automysqlbackup.conf
However, when I look at the command output, they are still there -
tar: Option --after-date: Treating date `2016-01-01' as 2016-01-01 00:00:00
tar: Removing leading `/' from member names
...
/home/bamboo/automysqlbackup
/home/bamboo/automysqlbackup.conf
...
Why is it not filtering these files by dates correctly?
Thanks.
已采纳解答
原帖链接 · A.B · CC BY-SA 3.0
Reading the gnu documentation: https://www.gnu.org/software/tar/manual/html_node/after.html
[...] causes tar to only work on files whose data modification or status change times are newer [...]
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.
So I guess if you check your files with ls -lc /home/myhome rather than ls -l you'll see their ctime (that would be status in the documentation) is newer than your date
ctime changes when the inode changes, including but not limited to actions such as chmod, ln (hardlinking), and of course creation, like restoration from a tar archive.
So try this instead:
tar jcvf archive.tar.bz2 --newer-mtime=2016-01-01 /home/myhome
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
