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

Thread: Simple question for someone who knows anything about zip

  1. #1
    Join Date
    Mar 2009
    Beans
    97
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Simple question for someone who knows anything about zip

    I'm writing a script that unzips an archive, edits it, and zips it back up.

    That being said, I've got it all figured out except for the zipping it back up.

    Code:
    unzip file.zip -d /tmp/foobar
    ##regexes###

    Now when i get to zipping the files back up, I don't want to include the /tmp/foobar directory I created. I want it to have the same tree as before.

    I've gotten two commands to come close, but not what I want.

    Code:
    zip -r /tmp/file.zip /tmp/foobar/*
    - this zips up the folders and files within /tmp/foobar/ however, it includes the /tmp/foobar tree.
    Code:
    zip -rj /tmp/file/zip /tmp/foobar/*
    - this gets rid of the directories, however, it gets rid of ALL the directories, and doesn't preserve any within /tmp/foobar.

    Now, by default zip will ignore /tmp/foobar if you're in that directory and running zip from there. But since this is a script I don't want to be limited to where I can run the script, or lower my standards to including changedirectory lines in my script. It seems to me like I should be able to 1-liner it, and it's frustrating me.

    Anyone use zip enough to be able to help me?

  2. #2
    Join Date
    Mar 2009
    Beans
    97
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Simple question for someone who knows anything about zip

    bump?

  3. #3
    Join Date
    Sep 2005
    Location
    Montréal,Québec
    Beans
    149
    Distro
    Kubuntu 11.04 Natty Narwhal

    Re: Simple question for someone who knows anything about zip

    Bumping after 30 minutes is a bit excessive there ...

    Your command "zip -r /tmp/file.zip /tmp/foobar/*"
    tells to zip everything in the /tmp/foobar/ directory into /tmp/file.zip.

    You want to *exclude* that folder, so you must specify it with the -x (see man pages).

    It would thus look like :
    zip -r /tmp/file.zip /what-you/want-to-zip/* -x /tmp/foobar/*

    If there are many directories you wish to exclude, you could create a file named "exclude.lst", include all the directories to be excluded, and write :
    zip -r /tmp/file.zip /what-you/want-to-zip/* -x@exclude.lst

  4. #4
    Join Date
    Sep 2009
    Location
    Freiburg/Germany
    Beans
    1,112
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: Simple question for someone who knows anything about zip

    Quote Originally Posted by yaroto98 View Post
    I'm writing a script that unzips an archive, edits it, and zips it back up.

    Now, by default zip will ignore /tmp/foobar if you're in that directory and running zip from there. But since this is a script I don't want to be limited to where I can run the script, or lower my standards to including changedirectory lines in my script.
    Why you don't want to use cd in a script?
    ClassicMenu Indicator - classic GNOME menu for Unity
    Unsettings - configuration program for the Unity
    Privacy Indicator - easily switch privacy settings in Unity
    Arronax - create and modify app starters

  5. #5
    Join Date
    Mar 2009
    Beans
    97
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Simple question for someone who knows anything about zip

    I did look at the man page, several times. However after trying every combination using -x I looked at the man page again looking for examples, and -x only excludes files, not directories.

    Any other ideas?

  6. #6
    Join Date
    Apr 2007
    Beans
    12

    Re: Simple question for someone who knows anything about zip

    Code:
    zip -r /tmp/file.zip /tmp/foobar/*
    - this zips up the folders and files within /tmp/foobar/ however, it includes the /tmp/foobar tree.

    Have you tried running the command from the /tmp/foobar directory?

    For example:
    Code:
    cd /tmp/foobar
    zip -r /tmp/file.zip *
    I would think that should fix your problem.

    By including the path in your zip command it will include the path in the zip file.

  7. #7
    Join Date
    Apr 2009
    Location
    Between Satan and Linus
    Beans
    91
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Simple question for someone who knows anything about zip

    Sry, didn't see first post. My answer was stupid. How do you delete a post?
    Last edited by Hikayu; April 9th, 2010 at 03:20 PM. Reason: didn't see first post
    Linux isn't necessarily the most efficient home Operating System. Quite the contrary.

  8. #8
    Join Date
    Feb 2006
    Location
    uk
    Beans
    Hidden!

    Re: Simple question for someone who knows anything about zip

    Quote Originally Posted by smartidiot View Post
    Code:
    zip -r /tmp/file.zip /tmp/foobar/*
    - this zips up the folders and files within /tmp/foobar/ however, it includes the /tmp/foobar tree.

    Have you tried running the command from the /tmp/foobar directory?

    For example:
    Code:
    cd /tmp/foobar
    zip -r /tmp/file.zip *
    I would think that should fix your problem.

    By including the path in your zip command it will include the path in the zip file.
    this seems like the best solution. set your path as a variable then you can use it when you unzip, and then again to change directory before zipping back up. if its always gonna be in /tmp/ then you dont even need to do that.

  9. #9
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,342
    Distro
    Ubuntu

    Re: Simple question for someone who knows anything about zip

    The above posters are correct; you need to change directory first.

    I don't know how changing a directory would "lower standards". You may find the commands pushd and popd useful, as they let you remember where you were before changing directory.
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  10. #10
    Join Date
    Mar 2009
    Beans
    97
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Simple question for someone who knows anything about zip

    I guess cd-ing isn't "lowering my standards", it just seems like I should be able to just say in one command "zip this directory and everything underneath it, and nothing above it". That doesn't seem like it's asking too much does it?

    More than anything it's become personal between me, my coworkers and zip....

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

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