Linux and UNIX view command-line history

by Vivek Gite [Last updated: March 18, 2008]

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

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 2 comments… read them below or add one }

1 approx_nice 03.18.08 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

2 vivek 03.18.08 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

Leave a Comment

You can 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>

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

Previous post: Linux setup default gateway with route command

Next post: How do I use shell aliases under Linux?