Zip
查找並壓縮單個文件並刪除原始文件
讓我們有一個包含許多單獨
.txt
文件的目錄。我的目的是在目錄中找到單個文件,分別用相同的名稱(不包括.txt)壓縮它們並刪除原始文件。它非常易於使用
gzip
,如下所示:find .* -type f | xargs gzip
但我需要壓縮文件。
注意:我沒有 sudo 權限
來自男人:
-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 use- ful 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.
壓縮目前目錄中的 ann 文件
zip -m test.zip *.txt
試試這個,
for i in *.txt; do zip -m "${i%.*}.zip" "${i%.*}".*; done
上面的程式碼將在 for 循環中獲取所有以 .txt 作為副檔名的文件,並使用它們的前綴名稱壓縮每個文件……