Linux and UNIX view command-line history

by Vivek Gite on August 6, 2006 · 11 comments

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).

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 11 comments… read them below or add one }

1 approx_nice March 18, 2008

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 vivek March 18, 2008

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

Not everyone uses bash, my friend.

Reply

4 sss January 16, 2009

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

Reply

5 Robert January 13, 2011

echo $HISTSIZE

will print to screen how long your history is.

Reply

6 Bingo June 14, 2009

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

Reply

7 clear history June 30, 2009

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

Reply

8 nishu July 23, 2009

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

9 Bob October 11, 2011

nishu, you shat?

Reply

10 Nataraj November 7, 2011

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

Reply

11 arun November 9, 2011

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

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 15 + 10 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: