Find the answer to your Linux question:
Results 1 to 5 of 5
I have a lot of zip files I need unzipping that have spaces in their name. Code: for z in *.zip; do unzip $z; done Does fine except it unzips ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    LRC
    LRC is offline
    Just Joined! LRC's Avatar
    Join Date
    Apr 2009
    Posts
    13

    Batch unzip


    I have a lot of zip files I need unzipping that have spaces in their name.
    Code:
    for z in *.zip; do unzip $z; done
    Does fine except it unzips into the main folder. That is not good as it confuses things and I have multiple files with the same name. Is there a command that will create a new folder with the same name as the zip file?
    I do know that ark can do that with the -ba commands BUt I do not know how to get around the problem of spaces in names.

  2. #2
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    661
    Quote Originally Posted by LRC View Post
    I have a lot of zip files I need unzipping that have spaces in their name.
    Code:
    for z in *.zip; do unzip $z; done
    Does fine except it unzips into the main folder. That is not good as it confuses things and I have multiple files with the same name. Is there a command that will create a new folder with the same name as the zip file?
    I do know that ark can do that with the -ba commands BUt I do not know how to get around the problem of spaces in names.
    Code:
    ls -1 *.zip | while read zipname; do mkdir "${zipname%.zip}" ; { cd "${zipname%.zip}" && unzip ./../"${zipname}" ) } ; done

  3. #3
    LRC
    LRC is offline
    Just Joined! LRC's Avatar
    Join Date
    Apr 2009
    Posts
    13
    Tried and got:
    Code:
    bash: syntax error near unexpected token `)'
    As I am a total noobie to code and get lost very fast in any manual reading, I have no clue what is missing.
    PS: Must say though that I love linux because it is far superior in many ways to Windows and saves a bundle on hardware. Once I do figure out what to do I do use console for a lot of things.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187
    unzip -e *.zip

  6. #5
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    use the -d flag to tell unzip to make a directory. make the directory name based off the zip filename, e.g.:

    Code:
    #!/bin/bash
    for zip in *.zip; do
      dir=$(basename $zip .zip)
      unzip -d $dir $zip
    done

Posting Permissions

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