2014-02-27 44 views
0

我需要找到我的目錄下的文件,並以相同的名稱壓縮它們。從一個目錄中壓縮文件

我試圖下面

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 

在此先感謝。

+0

遺憾。我的回答很糟糕。沒有閱讀你的編輯 – 2014-02-27 19:46:53

回答

0

試試這個:

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

你很可能會覆蓋原來的文件,需要提供一個擴展您的郵政編碼。

0

您可以使用execdir選項:

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