Configuration Information [Automatically generated, do not change]: Machine: i686 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib -g -O2 -Wall uname output: Linux dragonfly 2.6.35-27-generic #48-Ubuntu SMP Tue Feb 22 20:25:29 UTC 2011 i686 GNU/Linux Machine Type: i686-pc-linux-gnu
Bash Version: 4.1 Patch Level: 5 Release Status: release Description: Bash truncates HISTFILE (~/.bash_history) to zero bytes when the filesystem is full. Repeat-By: Use bash with a full HISTFILE (ie, one that has HISTFILESIZE lines in it) and a full disk. The HISTFILE is empty afterwords. Long, drawn out, concrete example including making a new test user with a home directory on a separate filesystem so it can be easily and harmlessly filled up: $ # Create a new user with a home dir on a small temporary filesystem $ sudo adduser bashbug Adding user `bashbug' ... Adding new group `bashbug' (1002) ... Adding new user `bashbug' (1002) with group `bashbug' ... Creating home directory `/home/bashbug' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for bashbug Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] $ dd if=/dev/zero of=/dev/shm/bashbug-home bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10 MB) copied, 0.0332525 s, 315 MB/s $ mke2fs /dev/shm/bashbug-home mke2fs 1.41.12 (17-May-2010) /dev/shm/bashbug-home is not a block special device. Proceed anyway? (y,n) y Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 2560 inodes, 10240 blocks 512 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=10485760 2 block groups 8192 blocks per group, 8192 fragments per group 1280 inodes per group Superblock backups stored on blocks: 8193 Writing inode tables: done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 31 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. $ sudo mount -o loop /dev/shm/bashbug-home /dev/shm/bashbug-home-mnt $ sudo mv -v /home/bashbug/* /home/bashbug/.??* /dev/shm/bashbug-home-mnt/ `/home/bashbug/examples.desktop' -> `/dev/shm/bashbug-home-mnt/examples.desktop' removed `/home/bashbug/examples.desktop' `/home/bashbug/.bash_logout' -> `/dev/shm/bashbug-home-mnt/.bash_logout' removed `/home/bashbug/.bash_logout' `/home/bashbug/.bashrc' -> `/dev/shm/bashbug-home-mnt/.bashrc' removed `/home/bashbug/.bashrc' `/home/bashbug/.profile' -> `/dev/shm/bashbug-home-mnt/.profile' removed `/home/bashbug/.profile' $ sudo chown bashbug:bashbug /dev/shm/bashbug-home-mnt $ sudo umount /dev/shm/bashbug-home-mnt $ sudo mount -o loop /dev/shm/bashbug-home /home/bashbug $ df Filesystem 1K-blocks Used Available Use% Mounted on ... /dev/loop0 9911 99 9300 2% /home/bashbug $ $ $ $ $ # Fill up .bash_history and let bash trim it to HISTFILESIZE $ sudo -u bashbug -i bashbug$ yes | head -n 3000 > .bash_history bashbug$ echo $HISTFILE $HISTSIZE $HISTFILESIZE # The defaults /home/bashbug/.bash_history 1000 2000 bashbug$ wc -l .bash_history 3000 .bash_history bashbug$ logout $ wc -l /home/bashbug/.bash_history 2000 /home/bashbug/.bash_history $ $ $ $ $ # Fill up the filesystem $ sudo bash -c 'yes > /home/bashbug/full' yes: standard output: No space left on device yes: write error $ $ $ $ $ # On next use, .bash_history becomes empty: $ sudo -u bashbug -i bashbug$ whoami # Any command bashbug bashbug$ logout $ ls -l /home/bashbug/.bash_history -rw-r--r-- 1 bashbug bashbug 0 2011-03-20 17:08 /home/bashbug/.bash_history Fix: Bash should write out the new HISTFILE before destroying the existing one. That way, if writing the new one fails, the old one can be left intact.