
我必須從資料夾 A 中單獨壓縮一些文件,然後將它們移動到同一目錄中的資料夾 B,這需要花費大量時間。所以我想將所有要壓縮的檔案移到一個新資料夾(c),將其壓縮並移動到資料夾 B 。是否可以用很少的命令來完成它?歡迎提出建議。
答案1
shell 類型的腳本可能可以幫助您:
enter code here
mv <file.a>...<file.n> <new_folder>
zip -r <new_folder>
mv new_folder.zip /destination_folder
答案2
cp -R (the path of the folder to copy) (the name of the copied file)
然後
zip -r (name your zip) (the name of the copied file)
範例場景:假設我想複製 WordPress 安裝的外掛程式並壓縮它們(當我位於 WordPress 的根資料夾中)。
我會做:
cp -R wp-content/plugins plugins_backup
然後檢查我會做:
ls -la
我將看到新目錄插件備份,我將壓縮它:
zip -r plugins_backup.zip plugins_backup
準備好。 (然後按照mv的答案將其移動到任何地方)。
答案3
不知何故,我一直對 ZIP 檔案支援的 FUSE 外掛程式一無所知。它允許用戶掛載(或創建)ZIP 文件,就好像它是讀/寫文件系統一樣。
首先建立一個以 .zip 結尾的新(空)檔案並將其掛載到 /mnt。由於您希望 ZIP 檔案最終位於folder_B 中,因此我們將在那裡建立它:
# rm -f /folder_B/my_files.zip
# fuse-zip /folder_B/my_files.zip /mnt
您的貼文不清楚,但聽起來您希望 .ZIP 檔案包含folder_C,然後所有檔案都駐留在那裡。因此,我們將在 /mnt 上的 .ZIP 檔案內建立folder_C:
# mkdir /mnt/folder_C
現在您只需進入folder_A並將所有要壓縮的檔案移到/mnt/folder_C中:
# cd /folder_A
# mv file1 file2 ... fileN /mnt/folder_C
最後,卸載並檢查 ZIP 檔案:
# umount /mnt
# unzip -v /folder_B/my_files.zip
我意識到這看起來很複雜,但基本的四個步驟是:
# fuse-zip /folder_B/my_files.zip /mnt
# mkdir /mnt/folder_C
# mv /folder_A/file1 /folder_A/file2 ... /folder_A/fileN /mnt/folder_C
# umount /mnt
我並不是說這個方法比其他解決方案更好或更差,只是一種不同的方法。我希望你覺得它很有趣。