Cleanup files of well known type

Run this bash script from a directory full of files of well known type (e.g. doc, docx, pdf, jpg etc) and it will move those that linux file command doesn't recognize to a subdir PROBABLY-JUNK

This is usefull after recovery of deleted files where a lot of them are incorectly guessed as "good".
#!/bin/bash

function testfile() { echo Scanning dir `pwd` ls | sed -e 's/^.*[.]//' | sort | uniq | while read EXT; do echo " found extension $EXT" COUNT_TOTAL=`ls | grep "$EXT$" | wc -l` echo " $COUNT_TOTAL total .$EXT files. SCANNING..." file *.$EXT | grep "$EXT: data$" |sed -e "s/: .*//" > /tmp/to-delete.txt COUNT_DEL=`cat /tmp/to-delete.txt | wc -l` echo " $COUNT_DEL files to delete" if grep '[.]' /tmp/to-delete.txt; then echo " moving files to PROBABLY-JUNK" mkdir -p PROBABLY-JUNK && cat /tmp/to-delete.txt | xargs mv -t PROBABLY-JUNK fi done } testfile

This topic: KnowledgeBase > DataRecoveryCleanupFiles
Topic revision: 24 Feb 2021, ChristosLivas
Copyright © enLogic