find-corrupt-file.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # The PhotoRec may be useful in your case:
  4. # https://www.cgsecurity.org/wiki/PhotoRec
  5. # https://www.cgsecurity.org/wiki/TestDisk
  6. # Regarding audio files, this is what I would do: Install mplayer (if you don't have it already). It can play most of the A/V formats. If the file is broken, an attempt to play it will produce exit code > 0.
  7. # An example (quick and dirty) approach:
  8. # Run the following one-liner (the example is for .mp3, you can easily modify it for .wav or other formats if you need.
  9. rm ~/bad.lst
  10. find "$PWD" -iname '*.mp3' | while read f; do echo "mplayer -frames 20 ${f} || echo ${f} >> ~/bad.lst" >> check.sh ; done
  11. # I used -frames 20 option in order to let mplayer to play just a little bit of each file.
  12. # Run the check.sh produced in the previous step:
  13. # sh ./check.sh
  14. # In the bad.lst there will be a list of 'non-playable' files. You can dispose them with another one-liner:
  15. # cat bad.lst | while read f; do mv "${f}" /path/to/wastebin ; done
  16. # or
  17. # cat bad.lst | while read f; do rm "${f}"; done
  18. # Good luck!
  19. # Addendum / Errata
  20. # The corrected version of one-liner from point 1., which will handle complex file names, goes like this:
  21. # find <your_recovery_drive_mount_point> -iname '*.mp3' | while read f; do echo "mplayer -ss 10 -endpos 1 '${f}' | grep -iq failed && echo '${f}' >> bad.lst" >> check.sh ; done