0

For a first time I need to create an .sh for do something. My aim is to unzip a lot of zip folders, so I've wrote the script below:

for zipfiles in /downloads/*.zip; do unzip $zipfiles; done

I can unzip all but I noticed that there are some files with the same name and typing y I can ultimate the process.

There is a way to extract only files with a specific extension, like .docx, instead of the entire zip folder? I'm absolutely sure that there aren't .docx with the same name.

konsolebox
  • 72,135
  • 12
  • 99
  • 105
MaxDragonheart
  • 1,117
  • 13
  • 34
  • 2
    Sidenote: [variables should almost always be quoted in Bash to avoid word splitting and globbing](/a/10067297/4518341), so: `unzip "$zipfiles"`. – wjandrea Jan 06 '22 at 19:46

2 Answers2

2

You can specify a pattern:

for zipfiles in /downloads/*.zip; do unzip "$zipfiles" '*.docx'; done

Tested to work with UnZip 6.00.

You can also specify the -x option to exclude.

konsolebox
  • 72,135
  • 12
  • 99
  • 105
0

try this one, it can be useful for your purpose.

for zipfiles in /downloads/*.zip; do unzip -xo "$zipfiles" '*.docx' ; done

by this option overwrite files WITHOUT prompting.

rezshar
  • 570
  • 1
  • 6
  • 20