Blog/Bash Eternal History

From Forza's ramblings

2020-08-06: Bash Eternal History

Picture showing bright coloured stars and galaxies against the black space.
Astronomers using NASA's Hubble Space Telescope have assembled a comprehensive picture of the evolving universe – among the most colorful deep space images ever captured by the 24-year-old telescope.

I often forget that special command I used a while back, so I use Bash history to find out what I did. The problem is that by default, the history is not very long.

The solution is simple. Enable an eternal bash history!

## file: ~/.bash_profile or ~/.bashrc
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "

# Don't keep duplicate commands from filling up the history
export HISTCONTROL=erasedups
export HISTFILE=~/.bash_eternal_history

# save all commands to the history immediately instead of at logout, enables you to save history from multiple sessions at once.

So, to find something from your history you simply do

# history |grep btrfs
21726  [2020-08-04 19:56:10] btrfs fi us /mnt/6TB/
22074  [2020-08-06 12:41:26] btrfs fi df -s /mnt/systemRoot/snapshots/src.20200806T0001/
22075  [2020-08-06 12:46:28] btrfs fi du -s src.20200806T0001/
22076  [2020-08-06 12:47:56] btrfs fi du -s /media/usb-backup/volumes/src/src.20200806T0001/
22077  [2020-08-06 12:48:06] btrfs fi du -s /mnt/systemRoot/snapshots/src.20200806T0001/

And to execute one of the lines you do

# !21726
    Device size:                   4.54TiB
    Device allocated:              3.50TiB
    Device unallocated:            1.04TiB
    Device missing:                  0.00B
    Used:                          3.47TiB
    Free (estimated):              1.06TiB      (min: 548.68GiB)
    Data ratio:                       1.00
    Metadata ratio:                   2.00
    Global reserve:              512.00MiB      (used: 0.00B)
    Multiple profiles:                  no

Data,single: Size:3.48TiB, Used:3.46TiB (99.61%)
   /dev/sdc2       2.19TiB
   /dev/sdb2       1.28TiB

Metadata,RAID1: Size:9.00GiB, Used:5.04GiB (56.02%)
   /dev/sdc2       9.00GiB
   /dev/sdb2       9.00GiB

System,RAID1: Size:32.00MiB, Used:416.00KiB (1.27%)
   /dev/sdc2      32.00MiB
   /dev/sdb2      32.00MiB

   /dev/sdc2     534.67GiB
   /dev/sdb2     534.99GiB

GNU Bash manual

Forza (talk) 12:50, 6 August 2020 (UTC)