linux - 从目录中压缩文件

标签 linux shell zip

我需要在目录中查找文件并将它们压缩到相同的名称下。

我正在尝试以下操作

find . -name "ABC_*.txt" -mtime +30 -exec sh -c zip '{}' '{}' \;"

但是出了点问题。

基本上,如果 find 命令找到 3 个文件,则表示:

./ABC_1.txt
./ABC_2.txt
./ABC_3.txt

我需要 3 个 zip 文件:

./ABC_1.txt.zip
./ABC_2.txt.zip
./ABC_3.txt.zip

提前致谢。

最佳答案

试试这个:

find . -name "ABC_*.txt" -mtime +30 -exec zip "{}.zip" "{}" \;

您可能会覆盖原始文件,并且需要提供 ZIP 的扩展名。

关于linux - 从目录中压缩文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22078605/

相关文章:

linux - 如何使用 docker swarm 扩展具有多个暴露端口和多个卷的应用程序?

bash - shell脚本中的全局变量

javascript - 通过 express 将 zip 解压缩到文件夹 Node 中

PHP解压没有外部库

c++ - C++中的字符串类支持多少个字符?

linux - IO 重定向到另一个文件

windows - 如何在 Windows Git shell 中运行 ./script.sh?

shell - 如何读取文件的最后一个字并附加 ","(如果不存在)。 UNIX系统

java - ZipEntry归档

c - 如何使用 2 个应用程序同时连接两个智能卡读卡器