Linux: History command

You can see your command history on Linux just using command history:


and this should show you all commands which you have wrote with a line number on the beginning of the line.
You can redo those commands just with ! and writing number of that line which command you want to redo:


add date and time to history list:

export HISTTIMEFORMAT='%d/%m/%Y %H:%M:%S '

or finnish way:

export HISTTIMEFORMAT='%d.%m.%Y %H:%M:%S '

Ofcourse you can use grep with history example like this:

history | grep apt-get

and get only line which has apt-get on them.

If you think that your history list is too short or too long just say:


and you will see how long your history file is and if you want to change it just say:

export HISTSIZE=1000

at the command line to set your history size to 1000 lines.

If you just want to run again last command just do:


I don’t know any reason why to have duplicate lines on history so it’s probably good idea to say:

export HISTCONTROL=erasedups

which makes history not to save repeated commands

and if you want to clear your history just say:

history -c

There is many more things what you can do with history but for me this are the most usefull.

You can find more about history command here:

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



This site uses Akismet to reduce spam. Learn how your comment data is processed.