我需要在目录中查找文件并将它们压缩到相同的名称下。
我正在尝试以下操作
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/