MaxDragonheart
MaxDragonheart

Reputation: 1290

Extract only files with specific extension via bash

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.

Upvotes: 0

Views: 748

Answers (2)

rezshar
rezshar

Reputation: 630

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.

Upvotes: 0

konsolebox
konsolebox

Reputation: 75478

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.

Upvotes: 2

Related Questions