Linux Blog

Linux History Command

Filed under: General Linux,Linux Software — at 5:00 am on Wednesday, November 17, 2010

linux find command

History is great. How does the saying go?

“Those who forget about history are doomed to repeat it?”

If that’s the saying I think it is more fitting to say that for those who forget the Linux History Command are doomed to repeat typing. A lot. Seriously, the history command can help you remember the exact Linux find command with the intricate search options you typed a while ago. It could help you open up your x2x or x2vnc sessions after a reboot. Who knows what you’ll use it for. All this comes at a little cost, you’ll have to know how to use it.

Basically you just do everything as normal except when you want to get rid of history, say because you did a whois on that dirty domain name just to see if it was available. Not saying I’ve ever done that or anything though.

To do that you just do:

history -c

Before you go and erase all those embarrassing wgets you did of <insert your favorite celebrity here> If you run the history command with no options you will see everything you’ve done with a number beside it. Go ahead and do it now. Once you’ve done that pick a command, one that you’ll know wont cause any damage. Perhaps an ls. If the number beside it is 1337 type the following:


That’s exclamation 1337. This will cause the Linux History Command to repeat the command specified at 1337 of the history file. Apart from writing this, I’ve only used this a handful of times. It mostly comes in handy when you’re trying to create one line shell scripts.

You can repeat the last command in the history with a double exclamation “!!”

To view all of your history in a more friendly format you can use

history | more
history | less

using more with history doesn’t give you any more history. Its just a pager. Less as you guessed doesn’t give you less although I know plenty of high school students that wish it would.

sing the Linux History Command with the tail command doesn’t search for the history of the pictures of the hot tail you saved, but rather the last things in your history, or any number, starting from the bottom up. If you want to see the last 20 things you put in history do this:

history | tail -n 20

I don’t think I can to make a pun for head. Oh wait, I’ve got one. It does the exact same thing as tail, except it goes down on history. You can also do it from the head down by doing:

history | head

If you want to, you can also view the history in you’re favorite text editor by editing the .bash_history. For example:

vim .bash_history</p>
<p>If you want to find out if you've used the wrong text editor in the past do this:</p>
<pre lang="bash">history | grep emacs

If you see anything other than the command you just typed, you’re using the wrong text editor. Oh, that’s right. I went there. Again (Handy Linux Wallpaper).