I can't seem to locate recent commands I've run when I do Ctrl + R in my terminal, nor can I see them when I hit the up arrow.
It was a long command. Is there a length limit to what is stored? I may have used sudo. Is sudo history stored somewhere else? If so how do I access it?
Commands run successfully via sudo are logged with the syslog priority of
notice
and unsuccessful attempts are logged asalert
.In most distributions, what files the logging is directed to is identified by priority in
/etc/syslog.conf
.With bash, there's a variety of environment variables that affect how the history operates. You can run the command
env
to see the current variables set in your shell's environment. Most variables controlling the bash history are prefixed byHIST
and are documented in the manual page. There's also shell options that affect how it operates. There's also a shell built-in command calledhistory
with various options. One of the main things that will affect whether or not history operates in an interactive shell is if theHISTFILE
variable is set. It's also notable that if the shell is not interactive, history will automatically not be enabled.Is this your problem?
If you had a space as the first character for the command, it would not have been saved to your history. I am pretty sure Ubuntu has this on by default.
There is a hidden file in each users home folder called ".bash_history" which contains a fairly extensive history of commands that have been run from that user account. This includes sudo commands.
If you know how to use the Vi text editor, you can type the following in the terminal to see the command history for your account: view ~/.bash_history
make sure
/home/greg/.bash_history
is set as -rw------- permissions (chmod 400). That might be the problem.Also, just try
rm /home/greg/.bash_history
and try again.Bash history is saved to that file ONLY AFTER quitting the session (but CTRL+R will work on it)
Lastly, ensure you press CTRL+R on a blank console (don't type your command first, type it AFTER pressing CTRL+R)