Friday, 9 December 2011

Delete your Linux history without leaving a trace!

Alright,

Second entry almost a full month later!

So, a while ago whilst I was trying to SSH into a Linux box from another Linux box I accidentally pasted the password into the console. Oh noes! Me, being the security conscious person I am, decided to delete the command via the # history -d [line entry number]. This of course leaves an entry in your history showing that you have deleted a line. Oh noes, Someone will see this and think I've been up to no good!

So I thought that I needed a way to delete a line from the history file without actually leaving this trace behind. The solution to this problem is this;

# history -d $((HISTCMD-1)) && history -d [line entry number]

Of course you could also use this command to run another command without it getting logged to the history file if you were so inclined;

# history -d $((HISTCMD-1)) && [type_your_command_here_and_execute]

Thanks to Mr b0nd for this awesome tip - http://www.garage4hackers.com/f28/linux-history-how-avoid-getting-logged-1032.html

Wednesday, 16 November 2011

OK - Let's try and get this started - Linux History Event Designator or Exclamation Mark!

Hi!

I started this blog with the intention that I could use it to keep track of useful IT related things that I pick up along the way as well as so that other people perusing the Internet may stumble upon them and possibly find them useful as well. I had a bunch of things back logged and half-stored in my (poor) memory and have now decided to ditch them and just post what I learned today.

So, today I was on the phone to a vendor trying to troubleshoot some problem that has been causing me grief for a very long time. Anyway, this Tech Guy is on the WebEx and I'm watching him doing all kinds of awesome debug. I'm particularly impressed by his mysql prowess (I must learn more about it!) but anyway, he goes and types "!wa" (minus the quotes) into this linux based appliance and I kind of recognise that what this has achieved is to search through his history of commands and then execute the last command in history that starts with "wa...".

I thought this was particularly awesome rather than using the arrow keys or the history command to go through your command history to find the massive line of code you just typed and wanted to type again without actually typing it!

A simple hint and perhaps obvious to some but I know for one, that I've looked through the Manual Page for the "history" command and never noticed this before. But look, there it is;


Event Designators

An event designator is a reference to a command line entry in the history list
! Start a history substitution, except when followed by a space, tab, the end of the line, `=' or `('.

Also, this blog came up when I searched google for [linux exclamation mark history] ;

http://www.codejacked.com/command-history-linux-mac-os-x/

Right, so that was the first disjointed post. And I probably will not post anything more! Let's see shall we?