![](/img/trans.png)
[英]Manipulate folder struct in a zip file ( linux && (bash || cgi script) ) without uncompressing
[英]How to zip file to a folder doesn't exist with bash script linux
我想將一個文件夾壓縮到一個不存在的目錄。 類似於
zip -r /home/unExistFolder/test.zip /home/logFolder
如果沒有這樣的文件夾,則創建文件夾。 如果有文件夾,則放入其中。
我怎么能知道呢?
newDir="/path/with spaces/to/archive"
if ! [[ -d "$newDir" ]] ; then
mkdir -p "$newDir"
fi
zip -r /home/unExistFolder/test.zip "$newDir"
某些版本的zip可能提供“如果目錄不存在,我將創建目錄”功能/選項,但是如果您希望某些東西可以一直工作,那么這是最好的選擇。
我將newDir
等於“ / path / newDir
/ to / archive”,以提醒您,如果不對變量的使用加dbl-quote,則會收到神秘的錯誤消息。 盡管在某些情況下,您不希望對變量使用dbl-quote,但通常應在shell腳本中對所有變量的用法使用dbl-quote。
高溫超導
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.