Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I run Ubuntu 12.04, and for some reason bash does not keep my command history. the ~/.bash_history file contains only 3 commands that I typed a few months ago.

How can I fix this?

EDIT: here's the relevant content of my .bashrc:

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
share|improve this question
Check your bash history settings in .bashrc. – jokerdino Oct 24 '12 at 15:18
@jokerdino thx, I edited the question. It's the standard settings (I didn't touch them). – yohbs Oct 24 '12 at 15:25
What is the output of "echo $SHELL"? – Aaron Oct 24 '12 at 15:25
@BryceAtNetwork23 /bin/bash – yohbs Oct 24 '12 at 15:26
Another thing to try is to check the permissions of ~/.bash_history – reverendj1 Oct 24 '12 at 16:48
up vote 15 down vote accepted

It could also be that root:root owns your .bash_history (ROOT SHOULDN'T BE THE OWNER, YOUR USER SHOULD BE THE OWNER!), in that case you need to:

$chown user:user .bash_history

This apparently could happen magically when you do sudo bash a lot!

share|improve this answer
Wow, I completely gave up on this and forgot about it... +1 and accept. – yohbs May 17 '13 at 19:04
Yeah this apparently happens when you do sudo bash a lot! :-) – mahatmanich May 22 '13 at 14:58

Assuming you're using gnome-terminal??, if so maybe check the permissions on .bash_history. It should be -rw-r--r--

To do so in a terminal ls -la |grep .bash, all 3 files should have the above permissions. Otherwise try deleting .bash_history, restart & see if a history is then written

Note that the history is only written once the terminal is closed or quit.

share|improve this answer

As commented above, this can be fixed with root->user ownership changes. Initial permissions may be from -rw-r--r-- or any other variation and root ownership.

In my case I only had .bash_history owned by root but it is all of .bash_* that must be owned by user.

share|improve this answer
Welcome to ask ubuntu :) This is a 3 years old answered question and the solution you mentioned already exists in another answer .. just vote it up :) – Ahmed Jerbi May 24 at 9:58

Your Answer


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.