Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I would like to have a log of all command that are typed on the terminal.

I have check "script" but this generates a file with the commands and the responds all together. Is there a way to have the commands only?

share|improve this question
    
Typed or ran? Ran: cat ~/.bash_history. Typed: echo use your memory. –  Lekensteyn Jan 24 '11 at 16:00
add comment

4 Answers 4

up vote 6 down vote accepted

If you are using the defaullt shells all the commands are already logged to $HOME/.bash_history . There are several environment variables which affect the history keeping, you can read about those with:

info bash
Type: / HIST

If you want to apply the setting to all users edit /etc/profile.

Example:

export HISTFILESIZE=5000
share|improve this answer
add comment

Everything a user types into the terminal by hand is saved into ~/.bash_history, where ~ is shorthand for the currenly logged in user's home directory. Note also that files beginning with a . are hidden; in Nautilus, you can show them by hitting Ctrl+H.

Take a look at it by typing

cat .bash_history

To view your history, annotated with sequential numbers, type

history

You can execute commands you see there again by typing !2129, for example, which would execute command number 2129 as shown by the history command.

Note that the history command shows you up to the second logs, wheras .bash_history is only saved after you log off from the terminal.

Little piece of interesting information:

  • Commands that begin with a space are not saved to .bash_history. If you run a command like rm -R mydir/, you may want to prefix it with a space to prevent accidentally running it again by hitting the up-arrow.

As Joāo says, the size of the saved history can be controlled with export HISTFILESIZE=5000.

share|improve this answer
    
However important to remember that if shell terminates abnormally, for example, because of network problems, firewall changes or because it was killed, then no history is written. –  user01 Feb 22 at 15:04
add comment

If you mean you want a log of all commands you run in an interactive shell, see BashFAQ 88 - How can I avoid losing any history lines?

share|improve this answer
add comment

You can also use CTRL+R in the terminal to search your history.

  1. CTRL+R
  2. enter search terms (e.g. type 'sudo apt-get')
  3. press CTRL+R to cycle through each match
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.