Where's the Fun in That?
Any solution starts with a problem. In my case, that problem is how do I find duplicate files in a directory on a Linux server? “Easy”, you may say, “Just write a python script”, or “There’s an app for that”. Fair enough, but where’s the fun in that? Why not challenge yourself? Let’s do it in a single bash line!! Here’s the beautiful, and ugly mess I came up with: find /root/ -type f -exec md5sum '{}' \; > md5.txt && cat md5.txt | sort -u -k1 | cut -d' ' -f1| uniq -c | awk 'int($1)>1' | sort -rn | awk '{print $2}' > 2uniq.txt && md5s=$(cat 2uniq.txt) && for md5 in $md5s; do grep $md5 md5.txt; done >> matches.txt Let’s break the command, and make since of it, but before that a few bash basics. A pipe | takes the results from a previous command and runs it against another command. The && allow for a new series of bash commands to run on the same line. The highlighted section performs a find command aga...