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?

Desperatuss0ccus
  • 252
  • 1
  • 4
  • 9
Greg_the_Ant
  • 489
  • 7
  • 26

4 Answers4

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.

Warner
  • 23,756
  • 2
  • 59
  • 69
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.

Nathan Powell
  • 579
  • 2
  • 6
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

James T
  • 555
  • 1
  • 4
  • 9
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)

Felipe Alvarez
  • 193
  • 2
  • 12