Re: ZIP file check
By: Mindless Automaton to DOVE-Net.Unix_Discussion on Thu Dec 16 2010 04:34 pm
I am looking for an easy way to check through my filebase and move any
bad zip files to a specific directory. When I moved over from Win32 to linux (as the harddrive failed) it seems a number of files really didn't make it.
I imagine there is a way to script it, but I haven't a clue how. Any snippets online to do this?
Use /usr/bin/find to locate all the zip files,
/usr/bin/unzip to test them and /usr/bin/mv to move them into whatever destination you choose.:
for F in `find . -name "*.zip"`; do
unzip -t "$F" >/dev/null 2>&1 || mv "$F" /destination/directory;
done
You can type this as three separate lines at the shell prompt. The shell will wait for the third line ("done") before executing the whole lot. Just get your punctuation right! Yes, those are back-ticks around the find command! :-)
Note this searches in "." (current directory) and subdirectories, so if you want to search elsewhere change the find command to suit. Use "/" (no quotes) to search the entire disk.
Also, this searches for .zip files and not .ZIP files or .Zip files. Do multiple passes or change the find command to suit:
-name "*.zip" -o -name "*.ZIP" -o -name "*.Zip"
Good luck!
---
þ Synchronet þ Vertrauen þ Home of Synchronet þ
telnet://vert.synchro.net