Server Fault is a question and answer site for system and network administrators. 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

I am attempting to use the zip -r command to zip a folder which includes two files. I need to pass the absolute path of the folder with two files (/path/to/my/files/), which is causing all of the folders to be zipped with it, where as I only need the last folder (files/) and its contents to be zipped, so that when the file is unzipped, there is only one folder and the two files within it. How can I modify the command to be able to pass the absolute paths in the arguments while keeping only the last folder?

share|improve this question
up vote 4 down vote accepted

zip operates from the current working directory. If you have to return to the working directory you started from, that can work too.


cd /path/to/my
zip -r files/
cd -
share|improve this answer
Thanks, I didn't think it would be that simple :/ – Preston Jun 11 '12 at 21:02
@Preston No problem, simple things can trip up anybody sometimes. It's not like the zip -h output is all that helpful to begin with. – Hyppy Jun 11 '12 at 21:04

Your Answer


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.