焦油和 --newer/--after-date 参数 [英] Tar and --newer / --after-date parameter

查看:35
本文介绍了焦油和 --newer/--after-date 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目结构如下:

-sprint41
 -file1
 -file2
-sprint40
 -file1
 -file2

  • 我在 sprint41 文件夹中的所有文件(+ sprint41)的修改日期为 20130807
  • 我在 sprint40 文件夹中的所有文件(+ sprint40)都有一个修改日期20130610
  • 我想创建一个存档,包括 20130715 之后的所有文件(+文件夹).我的命令如下:

    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 *
    

    在这个命令之后,test.tar 包含以下内容:

    After this command, test.tar contains the following:

    -sprint41
     -file1
     -file2
    -sprint40
    

    即使修改日期在 20130715 之前,它也会保留 sprint40 文件夹

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

    我期待以下内容:

    -sprint41
     -file1
     -file2
    

    你有线索吗?

    非常感谢

    推荐答案

    是的,问题是 tar 仍然会包含目录,即使它们是空的.它只是真正检查文件上的 --newer 选项,而不是目录.将不得不编写一个小脚本或使用带有 -cnewer 的 find 并将输出通过管道传输到 tar(在 tar 命令上使用 --no-recursion).

    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
    

    然后是这样的:

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

    这篇关于焦油和 --newer/--after-date 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆