Bash: Delete files listed in a text file

With so many unused py files in the project, I put together a few lines of code to get rid of them.

md5sum blank/
find -name "" -type f -exec md5sum {} + | grep 1fde9e174e80f7680d95dc905a3533a3 > empty_tests.txt

md5sum blank/
find -name "" -type f -exec md5sum {} + | grep 8c4eb991c6dca757bdd77f539092e29b > empty_models.txt

md5sum blank/
find -name "" -type f -exec md5sum {} + | grep ad656aaabae09dc285884ad38d889ef9 > empty_views.txt

# Delete any files listed in the text files
# awk splits up the md5 from the filename since md5sum output is "<hash> <filename>"
rm $(cat empty_*.txt | awk '{ print $2 }')

The first part collates a list of text files for any files with the common MD5 checksum.

In the second part:

  • cat reads in each empty_*.txt file
  • awk grabs the filename component of the checksum output
  • rm removes each filename returned by cat/awk


Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog