Enable Bash History in VCF Cloud Builder

VMware VCF

Enable history for the current session:

1admin@vcf-m01-cb01 [ ~ ]$ set -o history

Enable history on each login:

1admin@vcf-m01-cb01 [ ~ ]$ echo set -o history >> .bashrc

More info

Bash history is disabled by default (VCF 5.x).

To enable bash history in VCF Cloud Builder: SSH to Cloud Builder

1C:\>ssh admin@vcf-m01-cb01.lab2.vmw.one
2Welcome to Photon 4.0 (\m) - Kernel \r (\l)
3(admin@vcf-m01-cb01.lab2.vmw.one) Password:
4admin@vcf-m01-cb01 [ ~ ]$

You can check there's no .bash_history file:

1admin@vcf-m01-cb01 [ ~ ]$ ls -la
2total 20
3drwxr-x--- 2 admin vcf  4096 Feb 25 11:03 .
4drwxr-xr-x 5 root  root 4096 Feb 25 11:03 ..
5-rw-r--r-- 1 admin vcf   178 May  9  2024 .bash_logout
6-rw-r--r-- 1 admin vcf   643 May  9  2024 .bash_profile
7-rw-r--r-- 1 admin vcf   451 May  9  2024 .bashrc
8admin@vcf-m01-cb01 [ ~ ]$

You can check what is already enabled. Notice history off:

 1admin@vcf-m01-cb01 [ ~ ]$ set -o
 2allexport       off
 3braceexpand     on
 4emacs           on
 5errexit         off
 6errtrace        off
 7functrace       off
 8hashall         on
 9histexpand      on
10history         off
11ignoreeof       off
12interactive-comments    on
13keyword         off
14monitor         on
15noclobber       off
16noexec          off
17noglob          off
18nolog           off
19notify          off
20nounset         off
21onecmd          off
22physical        off
23pipefail        off
24posix           off
25privileged      off
26verbose         off
27vi              off
28xtrace          off

To enable Bash history, type set -o history.

1admin@vcf-m01-cb01 [ ~ ]$ set -o history

By default it will keep the last 1,000 commands, defined by $HISTSIZE. The .bash_history file will be truncated by the value of $HISTFILESIZE.

1admin@vcf-m01-cb01 [ ~ ]$ echo $HISTSIZE
21000
3admin@vcf-m01-cb01 [ ~ ]$ echo $HISTFILESIZE
41000

Add these lines to .bashrc to enable history on each login. (HISTSIZE/HISTFILESIZE optional):

1admin@vcf-m01-cb01 [ ~ ]$ echo set -o history >> .bashrc
2admin@vcf-m01-cb01 [ ~ ]$ echo HISTSIZE=2000 >> .bashrc
3admin@vcf-m01-cb01 [ ~ ]$ echo HISTFILESIZE=2000 >> .bashrc

Now you can press the up arrow and review the history by typing history and more.

Deleting history

If there's something you don't want in history, you can delete specific line(s), or wipe it all out.

Delete specific Bash history line history -d <line number>:

1admin@vcf-m01-cb01 [ ~ ]$ history -d 18

Delete a range of history lines.

1admin@vcf-m01-cb01 [ /home ]$ history -d 11-18

Delete all Bash history. The -c option clears the current history session and -w writes the current history session to .bash_history.

1admin@vcf-m01-cb01 [ ~ ]$ history -c
2admin@vcf-m01-cb01 [ ~ ]$ history -w

Check out the official Bash Reference Manual for more.