Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In my script, I call the zip-command with the full path of the archive and the target directory like so:

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

The tmp_build_dir_1344856484-directory tree looks as follows:

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

My problem now is, that I need the root of the zip-archive to have the XML file and the ressources-folder, but currently, the archive also includes the full path name.

# 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

How can I truncate the path just to a certain level so I can keep the sub-folder but not have the whole directory tree in it?

share|improve this question
    
I ended up changing the work-directory like explained here –  Lukas Knuth Aug 16 '12 at 12:13
add comment

1 Answer 1

Try this:

$ cd /srv/www/htdocs/xxx/system/tmp/build/tmp_build_dir_1344856484/
$ zip -r ../tmp_build.zip .
share|improve this answer
    
It's probably better to use a subshell in scripts to do not modify current working directory, like (cd $long_path && zip -r ../tmp_build.zip). Or one also can use pushd/popd for that. –  xaizek Aug 14 '12 at 6:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.