Recursively unzip archives to their respective folder

find . -name "*.zip" | while read filename; do unzip -o -d "`dirname "$filename"`" "$filename"; done;

0
By: ctcrnitv
2017-01-28 23:58:35

These Might Interest You

  • "unzip *.zip" doesn't work as expected, because unzip handle wildcards in a different way. You just need to escape the wildcard or do in another way: for f in *.zip; do unzip "$f"; done


    -4
    unzip \*.zip
    tiagofischer · 2009-03-26 02:36:28 1
  • Sometimes you unzip a file that has no root folder and it spews files all over the place. This will clean up all of those files by deleting them. Show Sample Output


    0
    unzip -l filename.zip |awk '{ if($4 != "Name" && $4 != "----") print $4}'|xargs -t rm -rf {}
    hk0i · 2011-10-20 18:54:15 0
  • Magic line will extract almost all possible archives from current folder in its own folders. Don't forget to change USER name in sudo command. sed is used to create names for folders from archive names w/o extension. You can test sed expression, used in this command: arg='war.lan.net' ; x=$(echo $arg|sed 's/\(.*\)\..*/\1/') ; echo $x If some archives can't be extracted, install packages: apt-get install p7zip-full p7zip-rar Hope this will save a lot of your time. Enjoy.


    0
    for ARG in * ; do sudo -u USER 7z x -o"$(echo $ARG|sed 's/\(.*\)\..*/\1/')" "$ARG" ; done
    n158 · 2012-12-31 19:47:24 0
  • unzips all zip files in any subdirectory under the current directory. The zip files are unzipped in their respective subdirs


    -3
    for f in `find ./ -name "*.zip"` ; do p=`pwd`; d=`dirname $f`; cd $d; b=`basename $f`; unzip $b; cd $p; done
    packetloss · 2009-05-30 03:42:53 4

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: