$ rm -rf test $ unzip test.zip -d test Archive: test.zip creating: test/zip_root/ extracting: test/zip_root/test.txt extracting: test/zip_root/test.1.txt
$ tree test test └── zip_root ├── test.1.txt └── test.txt
1 directory, 2 files
test.txt 並沒有被移除!!
看一下 zip 的說明:
$ zip -h2
Extended Help for Zip
See the Zip Manual for more detailed help
Zip stores files in zip archives. The default action is to add or replace zipfile entries.
The default action is to add or replace zipfile entries. → 因此不會刪除也是正常的
再仔細看一下 zip 的說明
Deletion, File Sync: -d delete files Delete archive entries matching internal archive paths in list zip archive -d pattern pattern ... Can use -t and -tt to select files in archive, but NOT -x or -i, so zip archive -d "*" -t 2005-12-27 deletes all files from archive.zip with date of 27 Dec 2005 and later Note the * (escape as "*" on Unix) to select all files in archive
-FS file sync Similar to update, but files updated ifdate or size of entry does not match file on OS. Also deletes entry from archive if no matching file on OS. zip archive_to_update -FS -r dir_used_before Result generally same as creating new archive, but unchanged entries are copied instead of being read and compressed so can be faster. WARNING: -FS deletes entries so make backup copy of archive first
-FS 似乎可以解決此問題: Also deletes entry from archive if no matching file on OS.
讓我們來試看看 -FS:
$ zip -ry -FS test.zip zip_root deleting: zip_root/test.txt
$ rm -rf test $ unzip test.zip -d test Archive: test.zip creating: test/zip_root/ extracting: test/zip_root/test.1.txt