截断归档中的绝对路径


0

在我的脚本中,我zip使用存档的完整路径和目标目录调用-command,如下所示:

zip -r /srv/www/htdocs/xxx/system/tmp/build/tmp_build.zip /srv/www/htdocs/xxx/system/tmp/build/tmp_build_dir_1344856484/

tmp_build_dir_1344856484-directory树如下所示:

+
|-- output.xml
|-+ ressources/
  |- some_file.png
  |- another_file.png

我现在的问题是,我需要zip-​​archive的根目录才能拥有XML文件和ressources-folder,但目前,存档还包含完整的路径名。

# Wanted path to some_file.png in zip-file:
/ressources/some_file.png
# What I currently get:
/srv/www/htdocs/xxx/system/tmp/build/tmp_build_dir_1344856484/ressources/some_file.png

如何将路径截断到某个级别,以便我可以保留子文件夹但不包含整个目录树?


我最终改变工作目录样解释这里
卢卡斯克努特

Answers:


0

尝试这个:

$ cd /srv/www/htdocs/xxx/system/tmp/build/tmp_build_dir_1344856484/
$ zip -r ../tmp_build.zip .

在脚本中使用子shell可能最好不要修改当前的工作目录,比如(cd $long_path && zip -r ../tmp_build.zip)。或者也可以使用pushd/popd它。
xaizek 2012年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.