5

When using the command line as root in Debian I get last commands executed as root. Where are those saved, what is the default file path and how can I find it?

thanks

12

If you're using bash (default shell in Debian) you can see all your recent history in the file ~/.bash_history (so .bash_history file in your local user)

Also from the command line you can type history and it'll also show you all your recent command history

3
  • 1
    Note that the file will not be updated immediately with default setting, but after closing the shell (bash in this case). – Lekensteyn Jan 31 '11 at 13:16
  • is there also a log with the full history? – Elzo Valugi Jan 31 '11 at 15:02
  • Unfortunately not, unless you configure bash for doing so it'll cut off your history. You can decide how many lines of history you get by adding this to your ~/.bashrc file export HISTSIZE=10000 (in this case I get 10,000 lines of bash history) – lynxman Jan 31 '11 at 15:04
9

The file you want is: /root/.bash_history

1
  • Haha, you beat me twice by 2 seconds, good answer sir ;) – lynxman Jan 31 '11 at 9:39
3

What others have said about .bash_history is right and proper, but it won't pick up commands executed as root with sudo. Those will be in the individual users' ~/.bash_history files (or other files, if they use other shells than bash).

2

Executing command with space in front, wont store command in history also.

3
  • 1
    This does not answer the question, but it's a really nice trick. Thanks, learned something new today :) – Lekensteyn Jan 31 '11 at 13:16
  • @user68884 interesting – Elzo Valugi Jan 31 '11 at 15:01
  • This can be controlled using the HISTCONTROL variable. – Dennis Williamson Jan 31 '11 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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