Extract Files With the Particular Extension From Zip Archive

Page content

“find” linux utility may be very handy if you’re trying to grind large number of files. Trying to remove many files in the particular directory using

$ rm -f ./*

you may get something like

/bin/rm: cannot execute [Argument list too long]

but if you use find, you won’t hit such an issue

$ find . -maxdepth 1 -delete

Today I was asked to extract .xml files from zip archives. There were lot of zip files and lot of files with different extensions within archives.

Here is a command I’ve utilized:

$ find . -type f -name "*.zip" -exec unzip -B {} *.xml \;

It searches for .zip file in the active directory and extracts .xml files from them. Currently processed zip file name substituted instead of “{}”, “;” shows end of the command to execute. unzip -B stores .xml files with matching names as filename.xml~, filename.xml~1, etc…