Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I created an Ubuntu virtualbox machine a couple weeks ago and have been working on projects off and on in it since then.

Now I would like to find the syntax of some commands I typed in the terminal a week ago, but I have opened and closed the terminal window and restarted the machine numerous times.

How can I get the history command to go back to the first command I typed after I created the machine, or is there another place that all the commands are stored in Ubuntu?

share|improve this question
2  
As far as I know you can't. You can only go back as far as the history buffer was set. If you're asking about what package you could install to indefinitely save command history in the future, perhaps you should revise your question. –  hbdgaf Jul 7 '12 at 6:35

4 Answers 4

It may or may not be possible to get all commands. It depends how many commands you executed and how the history limit was set.

However you can see the history list are stored here

/home/<YOUR_USERNAME>/.bash_history

Related question (for handling multiple shell history):

Is it possible to make writing to .bash_history immediate?

share|improve this answer
1  
It's not true that history is only saved from one terminal/shell. When you run history, it shows the current shell's history as most recent, and history from all other shells (including shells in previous sessions, including across power cycles) before that. All shell instances save their history to .bash_history when the exit. No instances save it there automatically, before that point. –  Eliah Kagan Jul 12 '12 at 2:57

Something that might also be of interest to you is how to search through your previous command history. You can reverse search your history on the command line by pressing Ctrl+r and then typing letters you wish to match. If you have more than one matching command, press Ctrl+r again. To quit the reverse search, press Ctrl+g.

http://www.ice2o.com/bash_quick_ref.html

share|improve this answer

By default, there is no place where all commands are recorded and kept indefinitely, although ~/.bash_history contains the past few commands (if you use bash, which is the default shell in Ubuntu).

If you want every command typed in bash recorded forever, you have to set it up yourself. For example, you can put the following in your ~/.bashrc file to log all the commands typed in a bash shell to the file ~/.command_log:

# log every command typed and when
if [ -n "${BASH_VERSION}" ]; then
    trap "caller >/dev/null || \
printf '%s\\n' \"\$(date '+%Y-%m-%dT%H:%M:%S%z')\
 \$(tty) \${BASH_COMMAND}\" 2>/dev/null >>~/.command_log" DEBUG
fi

The above sets a trap on DEBUG, which is executed just before an ordinary command is executed. The caller built-in is used to test whether the command is being typed at an interactive shell or run via something like ~/.bashrc. The value ${BASH_COMMAND} contains the command currently being executed.

share|improve this answer

You can only go back so far as your history limit is set; once it has reached that point the history will start to be overwritten. However, it is possible to have a larger history size for the future. Put this in your .bashrc and specify a value (mine is set at 1000):

export HISTSIZE=1000
share|improve this answer

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.