大网数据广告活动
服务器运维问答

Issue with tar -N command not filtering dates correctly

· 52CE 我爱测

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 automys…

问题原文

原帖链接 · 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 

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。