Linux and UNIX view command-line history

by on August 6, 2006 · 25 comments· LAST UPDATED March 18, 2008

in

Q. How do I view command line history? I am using Cent OS Linux system.

A. BASH is the default shell for Linux computers. Bash has history command. It display the history list with line numbers i.e. it lists everything you have entered on the command line. You can recall commands from history so that you can save the time.

Task: View your command Line History

Type the following command:

$ history
Output:

911  man  7 signal
912  man ps
913  man  7 signal
914  man killall
915  killall -l
916  man killall
917  su -
918  su - lighttpd
919  su - lighttpd
920  cd /tmp/
921  ncftpget -u 'vivek@lan.server.gite.in' lan.server.gite.in

So whenever you type a command, that command is saved is a file called .bash_history. Type following commands to get more info:
$ help history
$ man bash (look for Event Designators for more info).

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 25 comments… read them below or add one }

1 approx_nice March 18, 2008 at 6:12 am

How we can increase the size of History in Unix/Linux
Currently mine history command showing only 500 entries i want it to show atleast 2000 entries.

Thanks in advance

Reply

2 nixCraft March 18, 2008 at 8:55 am

Set HISTSIZE variable by editing ~/.bash_profile or other shell startup file.

HISTSIZE defines the number of commands to remember in the command history. The default value is 500. Set it to 2000
export HISTSIZE=2000

Reply

3 Ashesh August 10, 2011 at 1:16 pm

Not everyone uses bash, my friend.

Reply

4 Jacob August 20, 2012 at 12:33 pm

Most people do, my friend.

What is he supposed to do, spell out how to increase the size of your history in every single possible shell?

Reply

5 Charlie March 6, 2013 at 5:33 pm

Well said Jacob.. Besides vivek clearly said “or other shell startup file”
At the least one shoudl know which shell one is using…

Reply

6 sss January 16, 2009 at 9:47 pm

How do I determine the the size of my history file on the command line and how many commands that can be stored?

Reply

7 Robert January 13, 2011 at 7:32 am

echo $HISTSIZE

will print to screen how long your history is.

Reply

8 Bingo June 14, 2009 at 3:00 am

How do we clear the history? Do we set HUSTSIZE to ZERO and then back again to 2000 or so?

Reply

9 clear history June 30, 2009 at 11:15 pm

Hi Bingo,
use the following to clear the history:
history -c

Reply

10 nishu July 23, 2009 at 7:27 am

hi guys i am in need of a tutorial shat show how to automatically save history in a file every 1 second .
can any one assist me ..

Reply

11 Bob October 11, 2011 at 2:46 am

nishu, you shat?

Reply

12 Nataraj November 7, 2011 at 11:12 am

Display with data and time.
#export HISTTIMEFORMAT=’%F %T’
#history | more

Reply

13 Satish October 5, 2012 at 2:07 pm

Hi Natraj,

Can you explain more about this command. I tried executing but there was no output.

Thanks & Regards

Reply

14 Jay Nabonne October 8, 2012 at 2:06 pm

Be sure you don’t type the “#”‘s at the start of each line. That will turn them into comments!

Reply

15 arun November 9, 2011 at 12:25 am

i want to know how to see the particular user “s history when we lodin as a root

Reply

16 dinesh February 19, 2012 at 6:31 am

Hi friends, how can i get the complete info about a job that was running 10 days back?

pl Reply me…

Reply

17 dinesh February 19, 2012 at 6:34 am

How can i start a job after some time automatically?

Pl reply me…….

Reply

18 unghii false April 13, 2012 at 1:23 am

hello!

my history is delete when i log in. what i can do to keep the history?

Reply

19 Daniel September 19, 2012 at 8:42 pm

What is the command for pulling a specific line from history and running it again (without typing the whole command again)?

Reply

20 bang October 18, 2012 at 10:01 pm

by using bang. !254

Reply

21 Chiarnjiv February 28, 2013 at 7:30 am

Hi I want to display history of only 2 hours , How can I do it??

Reply

22 kHan June 18, 2013 at 3:06 pm

Hi all! any one can help me i want to see the all commands which is given by any user to my machine. if some one rm some file or other how can i see that which command was run on that machine. urgent plzzzz

Reply

23 Sachin September 18, 2013 at 5:15 am

Dear Friends,

I want to see the history with IP address.
Please help me to finding the solution.

Regards,
Sachin T.

Reply

24 dhiren June 13, 2014 at 10:40 am

how to dump data from tape to desk?
multiple files is there in tape.
i am no check eod
but dump all files how?

Reply

25 Martin July 15, 2014 at 4:43 am

Perhaps you could consider BASH history suggest box https://github.com/dvorka/hstr that greatly simplifies navigation through the history and its management.

Reply

Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: