创建zip而不记录根路径;编程

时间:2010-11-27 12:53:53

标签: bash shell zip

假设 我想拉这个目录 〔C:/用户/ xah / ErgoEmacs_Source / ergoemacs /积聚UTIL /〕

我想要输出目录 〔C:/用户/ xah / XX2 /〕

(我现在的目录可能在任何地方。我在elisp程序中调用zip) 所以我做了

zip -r c:/Users/xah/xx2/build-util.zip c:/Users/xah/ErgoEmacs_Source/ergoemacs/build-util/

然后zip将记录像这样的完整路径

adding: Users/xah/ErgoEmacs_Source/ergoemacs/build-util/ (stored 0%)
adding: Users/xah/ErgoEmacs_Source/ergoemacs/build-util/.svn/ (stored 0%)
adding: Users/xah/ErgoEmacs_Source/ergoemacs/build-util/.svn/all-wcprops (deflated 56%)
...

我希望路径只能以build-util开头。

注意:我在一个程序(elisp)中调用zip,我不能或不想使用任何envirenment变量的概念。

这是否可以使用一些zip参数?

2 个答案:

答案 0 :(得分:4)

奇怪的是,你最好的选择可能是使用Java JDK中的jar。

jar -cMf c:/Users/xah/xx2/build-util.zip -C c:/ Users / xah / ErgoEmacs_Source / ergoemacs / build-util /。

“-M”告诉jar不要创建清单文件,-C告诉它在开始压缩文件之前更改目录。我基于此的文档在这里: http://download.oracle.com/javase/tutorial/deployment/jar/build.html

答案 1 :(得分:4)

我最喜欢的一个bash函数是pushd,它会保存你当前所在的目录并将你移动到你指定的目录。弹出倒数函数,它会将您移回到推送之前的目录。 例如,你做

pushd c:/Users/xah/ErgoEmacs_Source/ergoemacs
zip -r c:/Users/xah/xx2/build-util.zip build-util/
popd

我认为你最终会得到你想要的东西。

相关问题