Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Zipping Multiple Files into Multiple Archives from Terminal

  1. #11
    Join Date
    Sep 2008
    Location
    Michigan, USA
    Beans
    193
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Zipping Multiple Files into Multiple Archives from Terminal

    No wrong way to do it. That's the beauty of *NIX!

    You could compile a file list first and use cat instead of ls and pipe that into a while loop.

  2. #12
    Join Date
    Sep 2008
    Location
    Michigan, USA
    Beans
    193
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Zipping Multiple Files into Multiple Archives from Terminal

    Or, use caution, ...

    Code:
    locate .gbc | while read file; do zip "${file}".zip "${file}"; done

  3. #13
    Join Date
    Apr 2009
    Location
    Cazenovia, NY, USA
    Beans
    22
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Zipping Multiple Files into Multiple Archives from Terminal

    Wow guys, thanks a lot.

    I started from the last post, made by KiLaHuRtZ, but unfortunately his command...

    Code:
    locate .gbc | while read file; do zip "${file}".zip "${file}"; done
    ...failed to do anything, no errors or anything.

    However, DaithiF's command...

    Code:
    for file in *.gbc; do zip "${file}.zip" "$file"; done
    ...works perfectly, and did exactly what I was looking for!

    I did not test the other two that you guy's posted, I think DaithiF's command is as simple as you can get, and it'll definitely help out if I ever have a problem like this again.

    And, thanks a lot, and I'm going to mark this as solved.

  4. #14
    Join Date
    Sep 2008
    Location
    Michigan, USA
    Beans
    193
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Zipping Multiple Files into Multiple Archives from Terminal

    Glad to hear it! DaithiF's is simpler for a single directory. The last one I posted should find all files with ".gbc" included in the string and zip them. Since it didn't work for you, my guess is that you power down often and may need to update the DB for the system to find them. Hence, run this first...

    Code:
    sudo updatedb
    locate .gbc | while read file; do zip "${file}".zip "${file}"; done

  5. #15
    Join Date
    Apr 2009
    Location
    Cazenovia, NY, USA
    Beans
    22
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Zipping Multiple Files into Multiple Archives from Terminal

    Ah yes, your command does work now. Thanks a lot for explaining that little problem.

    Just to simplify for anyone stumbling over this in the future:

    If all of the files you want to Zip are located in one directory, run this command:

    Code:
    for file in *.gbc; do zip "${file}.zip" "$file"; done
    ...And if the files you want to Zip are located in various directories, run this command:

    Code:
    sudo updatedb
    locate .gbc | while read file; do zip "${file}".zip "${file}"; done

    In the event you want to Zip files that are not .GBC files, replace .GBC with their file extension.

    And of course, a lot of thanks to KiLaHuRtZ and DaithiF!

Page 2 of 2 FirstFirst 12

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
  •