To backup my document root (/var/www/html/ I can execute):

zip -r ~/backups/all_zipped-$(date +\%F-\%T).zip /var/www/html/

The problem is that inside the created zip file, I get 3 base directories instead of 1:

  1. var.
  2. www.
  3. html.

The desired end state is to have only 1 base directory (the last one). In this case, of course, html (and its inodes).

Using zip -r ~/backups/all_zipped-$(date +\%F-\%T).zip /var/www/html/* (note the *), didn't help.

How to zip current directory without its entire path?

  • is there any particular reason why you're using zip rather than tar? do you need to share the backups with windows systems? – cas Jan 28 '18 at 8:32
  • Comfortability. Indeed, it's shared with Windows systems, there it's extracted by WinRAR. – pntshere Jan 28 '18 at 8:36
  • Add output of unzip -l ~/backups/all_zipped-$(date +\%F-\%T).zip to your question. If necessary, reduce the number of lines to the important lines. – Cyrus Jan 28 '18 at 9:14

By default, zip stores relative paths, not absolute ones, so if you perform the zip operation from the /var/www directory, you should get what you want. In the one-liner below, cd - returns you to whatever directory you were in before.

cd /var/www && zip -r ~/backups/all_zipped-$(date +\%F-\%T).zip html/ && cd -
| improve this answer | |
  • I don't see how my edit unix.stackexchange.com/review/suggested-edits/228048 does not improve the post even a little bit. Downvoting for the poor formatting you chose to retain. – Olorin Jan 28 '18 at 7:41
  • Current formatting is fine and your formatting didn't improve anything. – xenoid Jan 28 '18 at 15:05
  • @xenoid OP used GitHub-style triple-backtick formatting. That's not a proper code block in Stack Exchange Markdown. See how Cyrus's edit has changed. That's exactly what I tried to do. Please read unix.stackexchange.com/editing-help/#code and familiarize yourself with the formatting here. – Olorin Jan 29 '18 at 1:31

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