Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/ /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:
# What I currently get:

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

Try this:

$ cd /srv/www/htdocs/xxx/system/tmp/build/tmp_build_dir_1344856484/
$ zip -r ../ .
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 ../ Or one also can use pushd/popd for that. – xaizek Aug 14 '12 at 6:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .