How to zip a folder but not include it's parent directories?

I use “zip -r” to zip the following folder:

/root/Desktop/administration/backup

…My only grip is that when you open the zip file, the parent directories are there too.

So within the zip file I have to navigate through “/root/Desktop/administration” just to get to the directory called backup.

Is there a way for me to zip the directory backup, and not include the parent directories? I want to be able to open the zip file and see only the backup directory listed.

cd /root/Desktop/administration/
zip -r backup

PS. /root/Desktop seems a strange place to me to use for anything. Because root NEVER logs in in the GUI and that directory should accordingly never be used for it’s real purpose.

You can also use the -j option to “junk the path”

For more options check the man page.


man zip

Good luck,
Hiatt

When I use the zip -j option, it just errors out with “nothing to do”. I’ll keep researching.

Do you mean that my solution does not work either?

And when you want to give us usefull information, please do not TELL what you see, but SHOW what you see by copy/paste of the command and it’s output here in a post (of course between CODE tags: Posting in Code Tags - A Guide). Then there can be no misunderstanding about what happens.

hcvv’s solution should work fine, I was giving an alternative.

Try


zip -jr backup.zip /root/Desktop/administration/

Good luck,
Hiatt

The command I’m executing is:

zip -jr /root/Desktop/backupqueue/txhttp/$(date +%F).zip /root/Desktop/rsyc_cache/txhttp/

and here is the error I get:

    zip warning: name not matched: /root/Desktop/rsyc_cache/txhttp/zip
    zip warning: name not matched: /root/Desktop/backupqueue/txhttp/2011-05-11.zip
    zip warning: name not matched: /root/Desktop/rsyc_cache/txhttp/

zip error: Nothing to do! (try: zip -jr /root/Desktop/backupqueue/txhttp/2011-05-11.zip . -i /root/Desktop/rsyc_cache/txhttp/zip -jr /root/Desktop/backupqueue/txhttp/2011-05-11.zip /root/Desktop/rsyc_cache/txhttp/)

Use backticks instead.


zip -jr /root/Desktop/backupqueue/txhttp/`date +%F`.zip /root/Desktop/backupqueue/txhttp/

Good luck,
Hiatt

I repeat this only once more: copy/paste the complete text of he command and the output within CODE tags. See post #5 above.

That errors out to:

-bash: 2011-05-11: command not found
zip warning: first full name: /root/Desktop/rsync_cache/txhttp/orion/.htaccess
zip warning: second full name: /root/Desktop/rsync_cache/txhttp/orion/admin/.htaccess
zip warning: name in zip file repeated: .htaccess

zip error: Invalid command arguments (cannot repeat names in zip file)

…I find it weird that it would have issues with .htaccess now since it works fine with just the -r option.

Forget that last post, that won’t help.
I think zip doesn’t like your current working directory.
Change to root’s home and then run the command.


cd /root/
zip -jr /root/Desktop/backupqueue/txhttp/$(date +%F).zip /root/Desktop/rsyc_cache/txhttp/

Sorry about that.

Good luck,
Hiatt

your solution worked! Thanks!

Back ticks are only an old fashioned way of doing this. Thus nothing will be different as the result.

As I told you in post #2 :frowning:

I’m an airhead sometimes.

Thanks, I realized that after I posted, as I mentioned in post #11
I didn’t know backticks were old fashioned, I guess that makes me old fashioned. :slight_smile:

Not per se. It is on of those urban legends that is given down from one innocent noob to the next. Those people may however be very much up to date on other subjects. rotfl!

It was that way in the Bourne shell. Allready the Korn shell (about 25 years ago) offered the $( … ) feature, which has imho the advantages that it
. is better readable (especialy when a command/script also uses a multitude of ’ and " quoting;
. can be nested.

Actually according to the bash man page you can nest backticks also, by escaping them with , but I’m not interested in using this feature. Presumably if you want to nest on the second level, you would need to escape the \ too. Getting too much like watching Inception. Try this:

echo echo foo\echo bar``

Yep, works. I doubt if this works in the Bourne shell (but who has a Bourne shell nowadays). And since the Korn shell I happily use the $( … ). No incentive to go back because the readability of

echo $(echo foo$(echo bar))

is still much better imho.