I'm running CentOS 6.x and want to move the .bash_history to a different location.

The home directories of my users are (because I run a VPS) in /var/www/vhost/<domain>.<tld> which is FTP accessible (and it should be).

Because of this, I have changed the AuthorizedKeysFile for SSH connections out of the normal ~/.ssh/authorized_keys since FTP connections would easily be able to locate them.

At the same time I want to move the .bash_history file to /home/%u/.bash_history where %u is the current user.


You need to set HISTFILE for your users to the location you need, set the following in .bash_profile for the user, and for new users set it in the user skeleton directory, most likely /etc/skel/.bash_profile

export HISTFILE=/home/$USER/.bash_history
  • 1
    Thanks for how to set it up for new users automatically as well. – Brian Graham May 30 '14 at 20:23
  • As you are running a VPS I assumed it might come in handy. :) – Daniël W. Crompton May 30 '14 at 20:57
  • one note... this needs to be pretty early in the RC file parsing. As soon as anything gets written to history, any changes to this VAR are ignored. – Rich Homolka May 30 '14 at 21:04
  • @RichHomolka according to the man file changes to HISTFILE aren't ignored, notably: The name of the file in which command history is saved (see HISTORY below). The default value is ~/.bash_history. If unset, the command history is not saved when an interactive shell exits. – Daniël W. Crompton May 30 '14 at 21:21
  • @DaniëlW.Crompton I agree :) I use this to have separate history files based on the tty command. My point was WHEN you set it. At some point the location is fixed and further changes are ignored. – Rich Homolka May 30 '14 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.