Tar and --newer / --after-date parameter

北城以北 提交于 2019-12-24 16:28:50

问题


My project structure is the following:

-sprint41
 -file1
 -file2
-sprint40
 -file1
 -file2
  • All my files(+ sprint41) in sprint41 folder have a modified date 20130807
  • All my files(+ sprint40) in sprint40 folder have a modified date 20130610

I want to create an archive including all the files(+folder) after 20130715. My command is the following:

tar -cf test.tar --after-date 20130715 *

After this command, test.tar contains the following:

-sprint41
 -file1
 -file2
-sprint40

It is keeping sprint40 folder even though the modified date is before 20130715

I am expecting to have the following:

-sprint41
 -file1
 -file2

Do you have a clue ?

Many thanks


回答1:


Yeah, the problem is that tar will still include the directories even if they are empty. It's only really checking the --newer option on files, not directories. Going to have to either write a small script or use find with -cnewer and pipe the output into tar (with --no-recursion on tar command).

Create a file with the timestamp you want with

 touch -t 201307150000 timefile.txt

Then Somthing like:

find . -cnewer timefile.txt -print0 | xargs -0 tar --no-recursion -cf test.tar


来源:https://stackoverflow.com/questions/18108230/tar-and-newer-after-date-parameter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!