Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

Much thanks for any insight.

share|improve this question
    
SU question, I think. –  Charles Stewart May 26 '10 at 9:53
add comment

4 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
I'm not really sure if I put a space, but it was a command I copied from a webpage so it sounds plausible. –  Greg_the_Ant May 26 '10 at 2:56
add comment

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.

share|improve this answer
    
Is there any way to see commands I've run that seem to be missing from my history? –  Greg_the_Ant May 26 '10 at 2:57
    
Not if they were logged in the first place and are no longer in your terminal buffer. –  Warner May 26 '10 at 2:59
add comment

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

share|improve this answer
add comment

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)

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.