In Unix based systems like Linux and Mac OS X there are a number of ways of comparing two directories. The simplest way is to use diff:
diff –brief -rb directory_1 directory_2
This command compares each file and reports if they differ. You can find the meanings of the options in man diff.
Diff is fine if you’re on a fast drive, if there aren’t many files or the files aren’t big. The command compares the contents of each file so it can take quite some time on a slow external drive.
If you just want to know which files are in one directory and not in the other directory it’s overkill. This little bit of Bash scripting does that however:
diff <(cd dir1 && find | sort) <(cd dir2 && find | sort)
It still uses diff, but compares the file listing of each directory instead of the files. It’s much faster and perfect for figuring out what files are out of place on my 2 relatively slow USB drives. (source)
I wanted to know what IP addresses were hitting my website. I’d done this before and it only took a moment or two to recreate the following commands. Still, here it is for future reference.
grep -v "wp-content" access.log|grep -v wp-includes|cut -f 1 -d " "|sort|uniq -c|sort -nr|less
- Excludes “wp-content” and “wp-includes” requests.
- Uses “cut” to cut out the IP address.
- Sorts the list of IP addresses.
- Uses “uniq” to count the occurrence of each IP.
- And finally reverse sorts the list again, by number of occurrences, with the largest number at the top.
You’ll probably find Google and Yahoo! bots near the top of the list, but I also found the “Jyxobot/1″ bot was quite busy today.
How to loop over filenames with spaces – I knew this, but it had disappeared in the recesses of my brain.
Weather’s been bad for the past few days. No real opportunities for photography. Bah! At least I have 99% of my Christmas shopping done. Meanwhile, Mark has an entertaining piece on “The One Toy”.
Oh yes, If you’re over 20, buy RETRO, a (one off?) mag from games mag, Edge. It has great interviews with old Zzap64! staffers, bits on games of old (Elite anyone?) and other great stuff! If you’re under 20, you probably don’t know what I’m talking about. Hmm, scratch that, if you’re under 24 you probably don’t know what I’m talking about! Getting old ..