Skip to main content
Changed extract syntax to match actual option
Source Link
Shrout1
  • 461
  • 1
  • 6
  • 14

This is a nice bash one liner using default unzip:

 while read -r line; do (unzip -d "$(basename "$line" .zip)" "$line"); done < <(find . | grep '.zip')

Run this in the directory that has the zip files for unzipping.

  • The < < feeds the results of the find . | grep '.zip' into the while loop.
  • The filenames returned by find are then stored as line
  • The while loop iterates over the file names in line and feeds them into the do
  • This do creates a directory using the basename of the filename from $line
    • The .zip extension is specified as the text to be stripped off the string
    • This leaves only the name of the file without an extension (basename!)
  • The -d argument uses the basename of the .zip to create the new directory
    • /folder/archive.zip then becomes /folder/archive/unzipped_file.txt etc.
    • This is a lot like Windows / 7zip "extract all"to" option
  • The $line variable is then used as the target to unzip.

This one liner can be adapted for all kinds of things too! Moving files, zipping them, copying them... Find is recursive so it's super handy!

This is a nice bash one liner using default unzip:

 while read -r line; do (unzip -d "$(basename "$line" .zip)" "$line"); done < <(find . | grep '.zip')

Run this in the directory that has the zip files for unzipping.

  • The < < feeds the results of the find . | grep '.zip' into the while loop.
  • The filenames returned by find are then stored as line
  • The while loop iterates over the file names in line and feeds them into the do
  • This do creates a directory using the basename of the filename from $line
    • The .zip extension is specified as the text to be stripped off the string
    • This leaves only the name of the file without an extension (basename!)
  • The -d argument uses the basename of the .zip to create the new directory
    • This is a lot like Windows / 7zip "extract all" option
  • The $line variable is then used as the target to unzip.

This one liner can be adapted for all kinds of things too! Moving files, zipping them, copying them... Find is recursive so it's super handy!

This is a nice bash one liner using default unzip:

 while read -r line; do (unzip -d "$(basename "$line" .zip)" "$line"); done < <(find . | grep '.zip')

Run this in the directory that has the zip files for unzipping.

  • The < < feeds the results of the find . | grep '.zip' into the while loop.
  • The filenames returned by find are then stored as line
  • The while loop iterates over the file names in line and feeds them into the do
  • This do creates a directory using the basename of the filename from $line
    • The .zip extension is specified as the text to be stripped off the string
    • This leaves only the name of the file without an extension (basename!)
  • The -d argument uses the basename of the .zip to create the new directory
    • /folder/archive.zip then becomes /folder/archive/unzipped_file.txt etc.
    • This is a lot like Windows / 7zip "extract to" option
  • The $line variable is then used as the target to unzip.

This one liner can be adapted for all kinds of things too! Moving files, zipping them, copying them... Find is recursive so it's super handy!

find command now returns all .zip files in subdirectories not just one.
Source Link
Shrout1
  • 461
  • 1
  • 6
  • 14

This is a nice bash one liner using default unzip:

 while read -r line; do (unzip -d "$(basename "$line" .zip)" "$line"); done < <(find . | grep 'file'.zip')

Run this in the directory that has the zip files for unzipping.

  • The < < feeds the results of the find . | grep 'file'.zip' into the while loop.
  • The filenames returned by find are then stored as line
  • The while loop iterates over the file names in line and feeds them into the do
  • This do creates a directory using the basename of the filename from $line
    • The .zip extension is specified as the text to be stripped off the string
    • This leaves only the name of the file without an extension (basename!)
  • The -d argument uses the basename of the .zip to create the new directory
    • This is a lot like Windows / 7zip "extract all" option
  • The $line variable is then used as the target to unzip.

This one liner can be adapted for all kinds of things too! Moving files, zipping them, copying them... Find is recursive so it's super handy!

This is a nice bash one liner using default unzip:

 while read -r line; do (unzip -d "$(basename "$line" .zip)" "$line"); done < <(find . | grep 'file.zip')
  • The < < feeds the results of the find . | grep 'file.zip' into the while loop.
  • The filenames returned by find are then stored as line
  • The while loop iterates over the file names in line and feeds them into the do
  • This do creates a directory using the basename of the filename from $line
    • The .zip extension is specified as the text to be stripped off the string
    • This leaves only the name of the file without an extension (basename!)
  • The -d argument uses the basename of the .zip to create the new directory
    • This is a lot like Windows / 7zip "extract all" option
  • The $line variable is then used as the target to unzip.

This one liner can be adapted for all kinds of things too! Moving files, zipping them, copying them... Find is recursive so it's super handy!

This is a nice bash one liner using default unzip:

 while read -r line; do (unzip -d "$(basename "$line" .zip)" "$line"); done < <(find . | grep '.zip')

Run this in the directory that has the zip files for unzipping.

  • The < < feeds the results of the find . | grep '.zip' into the while loop.
  • The filenames returned by find are then stored as line
  • The while loop iterates over the file names in line and feeds them into the do
  • This do creates a directory using the basename of the filename from $line
    • The .zip extension is specified as the text to be stripped off the string
    • This leaves only the name of the file without an extension (basename!)
  • The -d argument uses the basename of the .zip to create the new directory
    • This is a lot like Windows / 7zip "extract all" option
  • The $line variable is then used as the target to unzip.

This one liner can be adapted for all kinds of things too! Moving files, zipping them, copying them... Find is recursive so it's super handy!

Source Link
Shrout1
  • 461
  • 1
  • 6
  • 14

This is a nice bash one liner using default unzip:

 while read -r line; do (unzip -d "$(basename "$line" .zip)" "$line"); done < <(find . | grep 'file.zip')
  • The < < feeds the results of the find . | grep 'file.zip' into the while loop.
  • The filenames returned by find are then stored as line
  • The while loop iterates over the file names in line and feeds them into the do
  • This do creates a directory using the basename of the filename from $line
    • The .zip extension is specified as the text to be stripped off the string
    • This leaves only the name of the file without an extension (basename!)
  • The -d argument uses the basename of the .zip to create the new directory
    • This is a lot like Windows / 7zip "extract all" option
  • The $line variable is then used as the target to unzip.

This one liner can be adapted for all kinds of things too! Moving files, zipping them, copying them... Find is recursive so it's super handy!