我需要查找大於45天的文件,將它們壓縮並將它們移動到壓縮文件夾並刪除原始文件。單命令查找文件,壓縮並移動到不同的位置,刪除原始文件
find . -name '*.dat' -exec zip '{}.zip' '{}' ';' -exec mv '{}' ~/archive/ \;
上面的命令似乎工作,但原始文件仍在文件夾中。
我需要查找大於45天的文件,將它們壓縮並將它們移動到壓縮文件夾並刪除原始文件。單命令查找文件,壓縮並移動到不同的位置,刪除原始文件
find . -name '*.dat' -exec zip '{}.zip' '{}' ';' -exec mv '{}' ~/archive/ \;
上面的命令似乎工作,但原始文件仍在文件夾中。
男人拉鍊
-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 '../{}' \;
上面的命令是好的,
順便說一句。爲什麼,然後移動到刪除?這似乎並不滿足。
你爲什麼不做一個很好的腳本? –
我有一個腳本來清理不同用例的文件,其中大部分都是一行。所以我儘管我會嘗試使用find將所有內容放在一行中。 – coolnags
您可以在腳本中創建一個功能。調用該函數也是1行。 –