My Azure Cloud Shell history does not persist across sessions (which time out after 10 mins so this is annoying). The .bashrc has

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

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)

So this should work, but no .bash_history gets written.

  • What is your Linux type? Ubuntu or other? Commented May 29, 2017 at 9:05
  • What is the current shell you use? You could check echo $SHELL Commented May 29, 2017 at 9:09

2 Answers 2


According to you description, it seems that your shell environment variable does not set correctly. I test on my Azure VM, it works for me. I suggest you could check as the following methods.

1.Check you current shell.

You could use echo $SHELL to get your current shell. .bashrc profile is used for bash shell. If you use other shell, such as csh, it does not work.

2.Check .profile file. Please ensure the following commands are existing.

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"

3.Check .profile and .bashrc user and group permission.

-rw-r--r-- 1 shui shui 3771 Aug 31  2015 .bashrc


Cloud Shell does not save history command to .bash_history. If you want to do this. You could add export PROMPT_COMMAND='history -a' to .bashrc. Such as belwo:

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

Then you could source .profile. Now, you could find .bash_histroy and store your latest history command.

Notes: It is not recommended to do this, because other people could see you command, this is unsafe behavior.

  • Hi - this is not a shell in a VM - it is the Cloud Shell. Thanks!
    – Gaius
    Commented May 31, 2017 at 9:19
  • @Gaius Thanks for you reply, I test in my lab, I could get .bash_history file. Could you get history command with history? Commented May 31, 2017 at 9:36
  • Only within the same session, which times out after 10 mins.
    – Gaius
    Commented May 31, 2017 at 9:51
  • @Gaius Sorry for my mistake, now, I know the reason. By default, Cloud Shell does not save history commands to .bash_history. If you want to do this, just add export PROMPT_COMMAND='history -a' to .bashrc. I updated it to my answer. You could check it. Commented Jun 1, 2017 at 6:48
  • Just checking in to see if the information provided was helpful. Please let me know if you would like further assistance. Commented Jun 5, 2017 at 9:19

As of now, bash history is written out on a successful exit of the bash process. In case of a premature timeout (increased to 20 minutes now), a history is not getting written out. It's a bug they are working on to fix.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .