Linux and UNIX view command-line history

last updated in Categories ,

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 ''

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

25 comment

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

      1. 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?

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

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

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

    1. Hi Natraj,

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

      Thanks & Regards

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

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

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

  7. Dear Friends,

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

    Sachin T.

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

    Still, have a question? Get help on our forum!