bash 如何在没有中间文件夹的情况下将文件添加到 zip 存档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15382303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add files to zip archive without a intermediate folder
提问by ibi0tux
I'm using zipprogram in a bash script and i would like to create an archive containing all files in a folder without adding the folder itself to the archive.
我zip在 bash 脚本中使用程序,我想创建一个包含文件夹中所有文件的存档,而不将文件夹本身添加到存档中。
I have such files :
我有这样的文件:
script.sh
files/
files/1
files/2
I'm using this command in script.sh
我在 script.sh 中使用这个命令
zip -q -9 -r arch.zip files/*
but this creates a filesfolder in the archive and i would like to get files 1and 2directly at the root of the archive.
但是这创造了一个files在存档文件夹,我想获得的文件1,并2在文件的根目录直接。
How can i modify the parameters passed to zipcommand to prevent it from adding filesin this archive ?
如何修改传递给zipcommand的参数以防止它添加files到此存档中?
Thanks
谢谢
FIXED :
固定的 :
Obviously, SO search engine is more efficient when the question is posted than before ...
显然,当问题发布时,SO 搜索引擎比以前更有效......
回答by Ansgar Wiechers
cd files
zip -q -9 -r ../arch.zip *
回答by user4619227
you should use -j key. Try this way:
你应该使用 -j 键。试试这个方法:
zip -q -9 -j arch.zip files/*
zip -q -9 -j arch.zip 文件/*

