1

I used a data recovery program to recover a bunch of overwritten text and the stuff that I want (previous versions of the overwritten files) is hidden amongst thousands of .txt, .json, .h and .html files.

Most of these unwanted files contain only one line of garbled text (even if they are megabytes in size), so it would be useful to have a tool that can quickly recognize those files and eliminate them.

(For background: some of the text that I want has been found within these recovered files, sometimes amidst truncated lines of code or complete garbage. No files containing only one line contain the text that I want, therefore I want those files to be eliminated.)

  • for clarification, some of the text that i want has been found within these recovered files, sometimes amidst truncated lines of code or complete garbage. no files containing only one line contain the text that i want, therefore i want those files to be eliminated. – Eric Leung Aug 18 '13 at 09:51
  • do you know about bash? try using bash – raindrop Aug 18 '13 at 10:14
  • 1
    What operating system? – evilsoup Aug 18 '13 at 10:20
  • whoops; this is for vista. i am unfamiliar with bash but eager to learn. i'll try out that bash script with a linux livecd later today, thanks! – Eric Leung Aug 18 '13 at 15:01

1 Answers1

1

You used photorec for the recovery, didn't you?

You didn't specify an OS but I'm going to assume Linux anyway.

Save script to /root/removebadfiles.sh (and chmod +x /root/removebadfiles.sh):

#!/bin/bash
file="$@"
lines=$(wc -l "$file" 2>/dev/null | awk '{print $1}');
if [ "$lines" = "1" ]; then 
  echo "$file"; 
  rm "$file"; 
fi

Recursive one-liner:

cd /path/to/files
find -type f -exec /root/removebadfiles.sh {} \;
justbrowsing
  • 2,659