【问题标题】:errors when piping a specific find command and creating a zipfile from its output?管道特定查找命令并从其输出创建 zipfile 时出错?
【发布时间】:2013-11-17 19:40:40
【问题描述】:

我希望创建一个程序来压缩在查找参数指定的目录中创建的任何文件,并将其作为后台进程运行。我对它进行了大量评论,以便更好地了解我正在努力实现的目标。我在我的 MacBook Pro 终端上运行它,OS X 版本 10.9

#!/bin/sh

#find file in directory listed below  
#type f to  omit  directories or special files  
#mtime/ctime is  modified/created  -0 days or less  
#name is with the name given in double quotes  
#asterik meaning any file name with any file extension  
#use xargs to convert find sequence to a command for the line after pipe  
find /Users/name/thisdirectory type f -ctime -0 -name "'*'.'*'" | xargs zip -

【问题讨论】:

    标签: macos shell unix zip pipe


    【解决方案1】:

    也许你正在寻找这个:

    find /path/to/dir -type f -ctime -0 -name "*.*" | zip -@ file.zip
    

    如果您阅读zip -h,它说明-@ 是从标准输入中读取文件名。

    这里不需要xargs,处理从标准输入接收的文件列表的功能内置于zip本身,类似于tar等大多数压缩工具。

    顺便说一句,我想你想改变-ctime -0,因为我不认为它可以匹配任何东西......

    【讨论】:

      猜你喜欢
      • 2021-10-24
      • 2019-11-08
      • 2014-08-30
      • 2011-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-06
      相关资源
      最近更新 更多