Hacker News new | comments | show | ask | jobs | submit login
Ask HN: Command Line History
10 points by Crontab 7 days ago | hide | past | web | favorite | 7 comments
In a past HN response to me, someone indicated that they keep a large history file for their shell. I have always set mine to not be created due to privacy concerns but this comment continues to stick with me.

For those who like to keep their command history: how much did you decide to keep and do you back it up and/or sync it?






One of the first things I do on a fresh install is set my history to two million lines:

    HISTSIZE=1000000
    HISTFILESIZE=2000000
I also have a one-line script "did" that searches for a pattern in the recent commands (from previous sessions):

    grep "$1" ~/.bash_history | tail
This is so simple but I couldn't begin to estimate how much time it has saved me over the years.

The history file is saved in my backups of home dir.

For what it's worth I sometimes am concerned with privacy, but it's important to remember that you must specify: privacy from whom?

For most cases I trust file permission flags, either only I'm root or someone else is and it wouldn't be appropriate to hide history from the sysadmin (i.e. on my employer's machines.)

- - - -

edit: TIL

> In bash 4.3 and later you can also use HISTSIZE=-1 HISTFILESIZE=-1


I keep an unlimited amount of my bash history using the method outlined in this stackoverflow answer[0]. I've been doing it for almost 2 years now now and my history file has about 50,000 commands and is under 2MB.

Maybe it makes ctrl-r more useful. Maybe I'll find something interesting to do with this data later, but it's pretty useless. It's a sort of personal diary I might scroll through years in the future.

For privacy, you could add something like this to your .bashrc

    alias forget="unset HISTFILE"
then invoke the "forget" command to stop saving commands in that shell session, including the "forget" command you just typed but not any command before that.

[0] https://stackoverflow.com/a/19533853/3064538


I have my bash history set to unlimited and there are currently 34489 entries in there. Since this is my development laptop and a machine that isn't normally accessible by anybody else, I don't worry too much about any security implications. And if the machine gets stolen, I'm screwed anyway.

OTOH, I hate knowing that I have used some obscure command or combination of commands and args in the past, and not having it in my history. It was after getting fed up over one such incident a couple of years ago that I changed my history settings to unlimited. I haven't regretted it yet.


In the Fish shell, your history feeds autocompletions so you can quickly run commands you ran in the past with a right-arrow keypress.

I personally use both ksh and fish (on different machines) and keep full history on fish and no history on ksh.


I keep all of it but I don't back it up. Disk is encrypted. Fancy commands go into Evernote for easier searching.

Also, I use fuzzy finder for cmd+r. Absolutely love it.


hi again https://news.ycombinator.com/item?id=17904390

your disk is probably encrypted anyway, so your risk is small. just be mindful to unset HISTFILE before things like exporting secret keys during development if you're so concerned.


Hello again.

I like the idea of unsetting HISTFILE to a avoid saving sensative commands. That probably works on most shells.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: