简体   繁体   中英

Single command to find files, zip and move to different location, delete the original files

I need to find files older than 45 days, zip them and move them to an archive folder and delete the original files.

find . -name '*.dat' -exec zip '{}.zip' '{}' ';' -exec mv '{}' ~/archive/ \;

Above command seems to work, but the original files are still in folder.

这里采用IPOR的想法是多样品和海峡find

find . -name '*.dat' -exec zip -m '~/archive/{}.zip' '{}' \;

man zip

  -m --move Move the specified files into the zip archive; actually, this deletes the target directories/files after making the specified zip archive. If a directory becomes empty after removal of the files, the directory is also removed. No deletions are done until zip has created the archive without error. This is useful for conserving disk space, but is potentially dangerous so it is recommended to use it in combination with -T to test the archive before removing all input files. 
find . -mtime +45 -name '*.dat' \
    -exec zip '{}.zip' '{}' ';' \
    -exec mv '{}' ../. ';' \
    -exec rm '../{}' \;`

Above command is fine,
btw.. Why, then move to delete? This seems not to be content.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM