I run this on my CentOs box:

zip -r backup.zip /home/user/domains/example.com/public_html/

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/example.com/public_html/. Does anyone know how to prevent this?

1 Answer 1


That looks like expected behavior, not strange behavior.

To get what you want, try this:

cd /home/user/domains/example.com
zip -r /srv/backups/example.com/backup.zip public_html
  • I run the above though a php script. Will what you suggest works with php exec ?
    – user146526
    Nov 28, 2012 at 15:10
  • Change directories with PHP's chdir() call instead of the cd command, then. Otherwise it's the same. Nov 28, 2012 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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