Using Multi-Byte Character Sets in PHP (Unicode, UTF-8, etc)
ENUMs, User Preferences, and the MySQL SET Datatype
Book Review: How to Implement Design Patterns in PHP
A Simple ISAPI Filter for Authentication on IIS
Visualising Website Performance with Flame Graphs
Using PHP pspell Spell Check Functions with a Custom Dictionary

Command-line PHP script to remove duplicates from bash history

Thursday, 29 November 12, 11:39 pm
For some reason, the erasedups option for bash history appears to have stopped working. Until I work out why and fix it, I wrote this PHP script to perform the same function.
#!/usr/bin/php <?php $history = file('/home/rdeeson/.bash_history'); $new_history = array(); for ($line = count($history) - 1; $line >= 0; $line--) { if (array_search($history[$line], $new_history) === false) { $new_history[] = $history[$line]; } } file_put_contents('/home/rdeeson/.bash_history', array_reverse($new_history));
It simply reads the current history file into an array, and creates a new array containing only the last occurrence of each history item which is then saved over the existing history file. I have it set to run every time my PC shuts down.

I don't know how long erasedups has not been working, Googling suggests it's not just me though. After running this script, the history file on one of my machines went from 10003 lines to 3746.

Please enter your comment in the box below. Comments will be moderated before going live. Thanks for your feedback!

Cancel Post

/xkcd/ Arizona Chess