The following simple command will browse through the tree of the current directory for various archive files and test their integrity. If the test fails, it'll print the file's path. You can easily extend it by adding more filename patterns and tests.
find . -type f \( \( -iname '*.zip' -o -iname '*.jar' -o -iname '*.war' -o -iname '*.ear' -o -iname '*.odt' -o -iname '*.ods' -o -iname '*.odp' -o -iname '*.docx' -o -iname '*.xlsx' -o -iname '*.pptx' -o -iname '*.xpi' \) -not -exec sh -c "unzip -t -P '' '{}' > /dev/null 2>&1" \; -o \( -iname '*.tar.gz' -o -iname '*.tgz' \) -not -exec sh -c "tar tzf '{}' > /dev/null 2>&1" \; -o -iname '*.tar.bz2' -not -exec sh -c "tar tjf '{}' > /dev/null 2>&1" \; -o -iname '*.tar' -not -exec sh -c "tar tf '{}' > /dev/null 2>&1" \; -o -iname '*.rar' -not -exec sh -c "unrar t -p- '{}' > /dev/null 2>&1" \; \) -print
This example relies on the availability of a few archive applications like
tar
,
unzip
and
unrar
. You should install them prior to running this command (on Debian/Ubuntu:
apt-get install tar unzip unrar
).
There're tons of file extensions that stand for ZIP archives (eg. JAR, ODT, DOCX files are all ZIP archives). I've provided a few examples (the ones that I meet every day), but it's far from complete. You should think it over what kind of ZIP archives you use and add your own file extensions to the list.
P.S.: the
-P ''
option for
unzip
and the
-p-
option for
unrar
make sure that neither of the two archivers ask for a password if they find a password-protected archive. Of course this means that these archives will be reported as broken too and from the simple filelist of the command's result you cannot tell which is broken and which is simply password-protected. You can adjust the command to process the output of
unzip
and
unrar
to distinguish between these two cases.
Recent comments
1 year 44 weeks ago
3 years 13 weeks ago
3 years 13 weeks ago
3 years 15 weeks ago
3 years 16 weeks ago
3 years 23 weeks ago
3 years 23 weeks ago
3 years 23 weeks ago
3 years 23 weeks ago
3 years 24 weeks ago