I need to find files i directory and zip them under the same name.
i am trying the following
find . -name "ABC_*.txt" -mtime +30 -exec sh -c zip '{}' '{}' \;"
But something is wrong.
basically if find command finds 3 files say:
./ABC_1.txt
./ABC_2.txt
./ABC_3.txt
I will need 3 zip files:
./ABC_1.txt.zip
./ABC_2.txt.zip
./ABC_3.txt.zip
thanks in advance.
Try this:
find . -name "ABC_*.txt" -mtime +30 -exec zip "{}.zip" "{}" \;
You are likely overwriting your original file and will need to supply an extension to your ZIP.
您可以使用execdir
选项:
find . -name "ABC_*.txt" -mtime +30 -execdir sh -c 'zip "$1.zip" "$1"' - '{}' \;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.