Hey everyone!

Today I have  something really basic but pretty useful tool and  it’s about the ‘history’ command.

Alright, so let’s start with The History Channel…oh! Command I meant…

The History command is a list (like a log) with all the recently executed commands, so let’s go to the practice!

Sometimes when you are working on a server environment or directly with the CLI (Command Line Interface) you need to check what was the last ‘entry’ into the system from the CLI, or you just can’t remember about a specific command that you made a few days ago so… the history command will help you with that.

Ok, first try to do the following into your terminal:

history

the results will be displayed on your screen, you should be able to see the whole bunch of commands that you have been used.

Ok now what if you try to remember what was the ‘user’ that you used to connect to the IP 192.168.1.9 (for example), so How can you check this one?

What we are gonna do is to mix two commands to make a super powerful one! oh yeah!

we will use the ‘grep’ command! Do you remember the Wilgeman’s podcast about the grep command? no?

(this is the link)

Ok, go back to the terminal and type:

history | grep “ssh”

So the results should be something like:

370 ssh root@192.168.1.3
376 ssh foo@192.168.1.9
384 ssh joe@192.168.1.31
389 ssh bush@192.168.1.5
391 ssh root@192.168.1.3

Now, let’s analize the results, let’s use the first line:

370 ssh root@192.168.1.3

the “370″ refers to the ‘event’ number, and the rest of the line describes the “event’.

 

Additional information

I have more info for you Players!  these are the places where your history file is located @ the different OSs:

Ubuntu:

Go to:

~/.bash_history

You can open that invisible file with nano/gedit/vi whichever.

 

this is what you see when you open the .bash_history file (Using nano):

 

Fedora/Mac OS X:

The same thing, go to your local directory (~) or do the following:

~/.bash_history

 

You can use ‘vi’ to open it like this:

[mckain@fedora16 ~]$ vi .bash_history

 

and the last thing! I have a ‘plus’ for you, Have you seen the movie ‘TRON’? Do you remember the part where Sam Flynn found that dusty machine and started to play with it?

alright he used the ‘history’ command! oh yeah! here’s a screenshot of that part XD:

 

So that’s pretty much it with the ‘history’ command, If you guys have any questions please let us know!

and remember this is a basic command but It’s really useful.

Have fun!

 

Tagged with →  
Share →

Leave a Reply

Your email address will not be published. Required fields are marked *


× two = 4

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by sweet Captcha