Clean ~/.bash_history with timestamp
If you have HISTTIMEFORMAT
set in your ~/.bashrc
, then your ~/.bash_history
file will have a unix timestamp recorded along with each comand, it is not easy to remove duplicate entries from it, below is a one-liner script that could do the work.
cat .bash_history | sed '$!N;s/\n/ /' | sort -s -k 2 | sed -n 'x; /^$/ {x;p;x;d;}; G; /\(#[0-9]*\) \(.*\)\n\(#[0-9]*\) \2$/ !{ s/^[^\n]*\n\(.*\)$/\1/; p; }; d' | sort -s | sed 's/^\(#[0-9]*\) /\1\n/' > bash_history.new
Written by Techlive Zheng
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Related Tags
#bash
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#