
這非常接近SO如何僅將壓縮存檔中的特定資料夾提取到給定目錄? 我需要一些接近的東西,但我總是得到包含內容的資料夾,而不僅僅是它的內容這是建議的:
#note $2 is passed in and would be == "magefoler"
unzip /srv/file.zip "$2-master/*" -d /srv/www/mage/
我需要做什麼來獲得具有這種結構的拉鍊
file.zip
|-magefoler-master/
|-magefoler-master/app/*tons of files
|-magefoler-master/skin/*tons of files
我需要將其移動到另一個資料夾,但是我無法移動magefoler
,我只想要app
和skin
資料夾。這並不意味著它總是這兩個資料夾,只是magefoler
我需要刪除其中的任何子內容、檔案或資料夾。試圖避免的是將所有內容匯出到一個資料夾,然後將其從那裡移動。
我正在尋找的最終結果來自我輸出到/mage
文件夾的 zip 文件,如下所示:
/srv/www/mage/
|--/mage/app/*tons of files
|--/mage/skin/*tons of files
答案1
你能不能直接解壓到這裡:
$ unzip /srv/file.zip "$2-master/*" -d /srv/www/
然後將資料夾移動/重命名magefoler-master
為mage
:
$ mv /srv/www/magefoler-master /srv/www/mage
備擇方案?
在過去研究這個確切的問題時,我只能找到兩種額外的方法來完成類似的事情,而不必求助於使用mv
.
- 依照 Gilles 的建議使用 FUSE:如何強制 unzip / zip 在解壓縮時不建立子目錄?
zipnote
在解壓縮之前,使用該工具移動 zip 檔案中的檔案。