Page 1 of 2 12 LastLast
Results 1 to 10 of 19

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

  1. #1

    Default 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.

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,003

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

    Code:
    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.
    Henk van Velden

  3. #3
    Join Date
    Aug 2008
    Location
    Behind the 8 ball
    Posts
    116

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

    You can also use the -j option to "junk the path"

    For more options check the man page.
    Code:
    man zip
    Good luck,
    Hiatt

  4. #4

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

    Quote Originally Posted by jthiatt08 View Post
    You can also use the -j option to "junk the path"

    For more options check the man page.
    Code:
    man zip
    Good luck,
    Hiatt
    When I use the zip -j option, it just errors out with "nothing to do". I'll keep researching.

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,003

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

    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.
    Henk van Velden

  6. #6
    Join Date
    Aug 2008
    Location
    Behind the 8 ball
    Posts
    116

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

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

    Try
    Code:
    zip -jr backup.zip /root/Desktop/administration/
    Good luck,
    Hiatt
    Last edited by jthiatt08; 11-May-2011 at 11:05. Reason: Fixed path

  7. #7

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

    Quote Originally Posted by jthiatt08 View Post
    hcvv's solution should work fine, I was giving an alternative.

    Try
    Code:
    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/)

  8. #8
    Join Date
    Aug 2008
    Location
    Behind the 8 ball
    Posts
    116

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

    Use backticks instead.

    Code:
    zip -jr /root/Desktop/backupqueue/txhttp/`date +%F`.zip /root/Desktop/backupqueue/txhttp/
    Good luck,
    Hiatt

  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,003

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

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

  10. #10

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

    Quote Originally Posted by jthiatt08 View Post
    Use backticks instead.

    Code:
    zip -jr /root/Desktop/backupqueue/txhttp/`date +%F`.zip /root/Desktop/backupqueue/txhttp/
    Good luck,
    Hiatt
    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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •