• andrew@lemmy.stuart.fun
    link
    fedilink
    English
    arrow-up
    16
    ·
    edit-2
    10 months ago

    I legitimately back up my history file. Mostly because it likes to truncate itself randomly (though this may have been fixed in zsh, or my config, because it’s been a while). Just a systemd timer that triggers a shell script to copy it by date and rotate anything older than 100 copies.

    Edit: WHY DID I SAY ANYTHING? After like 3 months of no problems, my history truncated itself to 3 entries a few minutes ago. I’ve only ever seen a few days of loss before that lol.

    • survivalmachine@beehaw.org
      link
      fedilink
      arrow-up
      9
      ·
      10 months ago

      history displays a list of all commands you have run on the terminal since the history list was last cleared. It is invaluable for referring back to a big complex command or set of commands you ran at some point in the past. The -c flag clears that history.

      • umbrella@lemmy.ml
        link
        fedilink
        arrow-up
        4
        ·
        10 months ago

        dont you also need history -w to save it?

        on ubuntu -c doesnt actually clear it unless you also use -w

        • survivalmachine@beehaw.org
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          10 months ago

          Yes, my comment only applies to the shell history in memory. -c clears history immediately, but you can still reload it from disk if you haven’t overwritten that with -w. If you tend to close your terminal windows frequently and rely on the history feature between sessions, it would benefit you to learn about the intricacies of the on-disk copy of history and how its affected by writes, appends, clears, crashes, etc. I tend to leave my terminal windows open a long time and copy any complex commands out to my PKM if I need to save them for future sessions, so I generally try not to rely on .bash_history, but it has saved my bacon on more than one occasion.

    • akdas@lemmy.world
      link
      fedilink
      arrow-up
      6
      ·
      edit-2
      10 months ago

      It lets you clear the bash command history, either completely or selectively. Here’s the GNU docs for the history builtin: https://www.gnu.org/software/bash/manual/html_node/Bash-History-Builtins.html#index-history

      (I’m not too familiar, someone else can clarify: is this available outside bash?)

      What’s interesting to me is the -a option, which lets you “flush” the history for the current session without ending the session. I can see that being useful!