Monday, 1 January 2018

Linux from the command line - the wonders of bash history

Linux from the command line - the wonders of bash history

This is a great reference for learning and exploring the power of the bash shell's history file.
I definitely recommend expanding the size of your history file, though I'm less enthusiastic in recommending messing with the history append setting. Also, even though they give the basic method for setting these things, you should read the manual for your Linux distribution and find the preferred way of setting these things for your distro.
https://www.digitalocean.com/community/tutorials/how-to-use-bash-history-commands-and-expansions-on-a-linux-vps

4 comments:

  1. Now that was worth reading! Searching without resorting to grep & getting back to the current prompt ... I knew they were out there, but hadn't got around to finding them. Thanks for the share.

    ReplyDelete
  2. I'll add these, which every Bash user should know:
    !* expands to all the words of the previous command line except the first.
    !$ expands to just the last word.
    ESC ^ expands any history references on the current command line without executing it yet.

    Incremental history is a productivity secret. Many times I've wanted to recall a complex command I ran about 3 months ago. Permanent incremental history makes that possible. It doesn't grow fast enough to be a storage problem.

    ReplyDelete
  3. Adrian Colley Thx, yeah there's a LOT more secrets to be dug from the shell.
    Regarding history, I usually set mine to unlimited for the reasons you stated. You never know when you'll need to dig up a complicated and obscure command line you used months ago, and the storage requirements are laughable given today's huge storage capabilities.
    As for incremental history though, I still stand by not recommending it for newcomers. At least not as done in the article. Once a person has concrete, official instructions specific to their distro and shell, then go for it.

    ReplyDelete
  4. Bruce Staples heh, that's why I posted it. I had to go refresh my own memory on some of these history functions and I actually came across a decent reference so I figured I'd better share it.

    ReplyDelete