Skip to main content
3 of 3
edited tags
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k

find "corrupt" file, nesting an if inside a find command

I'm trying to find "corrupt" files inside a directory structure, namely files which the file command would interpret as "data". Here is the command I've been trying to run, but fails:

$ find . -type f -exec if [[ $(file \{} | cut -f2 -d':') == " data" ]] \; then echo " \{}  is CORRUPT" \; else echo " \{} is DATA" \; fi \;
find: paths must precede expression: then

Does anyone know what I'm doing wrong here?

I realize I never saw an if inside an -exec parameter. Is it even possible?

Basically, I'm trying to find files that match that criteria (file would report it as "data", while not identifying a specific file type), and then list them, so that I can analyze before removing.

lolinux
  • 13
  • 1
  • 3