2

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?

1

4 Answers 4

2

Is this your problem?

HISTCONTROL A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ‘ignorespace’, lines which begin with a space character are not saved in the history list.

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.

1
  • I'm not really sure if I put a space, but it was a command I copied from a webpage so it sounds plausible. May 26, 2010 at 2:56
3

Commands run successfully via sudo are logged with the syslog priority of notice and unsuccessful attempts are logged as alert.

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 by HIST 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 called history with various options. One of the main things that will affect whether or not history operates in an interactive shell is if the HISTFILE variable is set. It's also notable that if the shell is not interactive, history will automatically not be enabled.

2
  • Is there any way to see commands I've run that seem to be missing from my history? May 26, 2010 at 2:57
  • Not if they were logged in the first place and are no longer in your terminal buffer.
    – Warner
    May 26, 2010 at 2:59
1

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

1

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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .