问题
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