Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 run this on my CentOs box:

zip -r /home/user/domains/

The command works ok as it should, but I have an annoying problem.

What I expect is when I open the zip to have one folder in it: public_html

Instead i have /home/user/domains/ Does anyone know how to prevent this?

share|improve this question
up vote 0 down vote accepted

That looks like expected behavior, not strange behavior.

To get what you want, try this:

cd /home/user/domains/
zip -r /srv/backups/ public_html
share|improve this answer
I run the above though a php script. Will what you suggest works with php exec ? – user146526 Nov 28 '12 at 15:10
Change directories with PHP's chdir() call instead of the cd command, then. Otherwise it's the same. – Michael Hampton Nov 28 '12 at 15:11
Excelent that works great! Thanks – user146526 Nov 28 '12 at 15:28

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.