我需要使用以下命令创建一个zip文件:
zip /dir/to/file/newZip /data/to/zip/data.txt
这是可行的,但是创建的zip文件会创建一个目录结构,模仿原始文件的目录。有很多我不需要的额外文件夹。
粗略地浏览一下手册页或谷歌搜索,我都没有找到答案。
发布于 2012-03-15 04:59:57
您可以使用-j
。
-j
--junk-paths
Store just the name of a saved file (junk the path), and do not
store directory names. By default, zip will store the full path
(relative to the current directory).
发布于 2017-03-08 20:15:41
在使用-r
选项时,使用-j
将不起作用。
因此,解决该问题的方法可以是:
cd path/to/parent/dir/;
zip -r complete/path/to/name.zip ./* ;
cd -;
或内联版本
cd path/to/parent/dir/ && zip -r complete/path/to/name.zip ./* && cd -
如果不希望cd -
输出显示在屏幕上,可以将输出定向到/dev/null
发布于 2012-03-15 05:01:39
使用-j
选项:
-j Store just the name of a saved file (junk the path), and do not
store directory names. By default, zip will store the full path
(relative to the current path).
https://stackoverflow.com/questions/9710141
复制相似问题