≡ Menu

Linux and UNIX view command-line history

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

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

{ 25 comments… add one }

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

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

    • Ashesh August 10, 2011, 1:16 pm

      Not everyone uses bash, my friend.

      • Jacob August 20, 2012, 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?

        • Charlie March 6, 2013, 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…

  • sss January 16, 2009, 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?

    • Robert January 13, 2011, 7:32 am

      echo $HISTSIZE

      will print to screen how long your history is.

  • Bingo June 14, 2009, 3:00 am

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

  • clear history June 30, 2009, 11:15 pm

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

  • nishu July 23, 2009, 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 ..

    • Bob October 11, 2011, 2:46 am

      nishu, you shat?

  • Nataraj November 7, 2011, 11:12 am

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

    • Satish October 5, 2012, 2:07 pm

      Hi Natraj,

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

      Thanks & Regards

      • Jay Nabonne October 8, 2012, 2:06 pm

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

  • arun November 9, 2011, 12:25 am

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

    • dinesh February 19, 2012, 6:31 am

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

      pl Reply me…

  • dinesh February 19, 2012, 6:34 am

    How can i start a job after some time automatically?

    Pl reply me…….

  • unghii false April 13, 2012, 1:23 am


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

  • Daniel September 19, 2012, 8:42 pm

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

    • bang October 18, 2012, 10:01 pm

      by using bang. !254

  • Chiarnjiv February 28, 2013, 7:30 am

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

  • kHan June 18, 2013, 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

  • Sachin September 18, 2013, 5:15 am

    Dear Friends,

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

    Sachin T.

  • dhiren June 13, 2014, 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?

  • Martin July 15, 2014, 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.

Leave a Comment

   Tagged with: , , , , , , , , , ,