24 ms·
Historian: Because Please Stop Deleting My Bash History
- dima55 9y agoOr, you know, put out the "random fires that burn down your history"
- bruce_one 9y agoI reckon last time I lost mine was a filesystem corruption (after a hard lockup), not sure how I'm going to put out that fire?
- forgotpwtomain 9y agoBackups on a different drive. Having an SQLite database in your home directory isn't really going to help you there (I mean as far as: if only parts of the filesystem are corrupt and you have re-duplicate entries, your chances are better of finding a working one - but it's hard to call that a solution).
- jcsalterego 9y agoI tried!
- bruce_one 9y agoLast time my .zsh_history was randomly emptied on me I was so so stranded - I felt helpless. I've now doubled-down on it and actually store lots of todo notes or receipt numbers or random snippets like that in my shell history as comments. It's just always there :-) And fortunately btrfs snapshots (and one time, a backup from a laptop migration...) have saved me form losing it for a long time now :-) Shell history is awesome, I'm always really intrigued when I see someone like a sysadmin who doesn't use shell history very well (read, at all...)
- forgotpwtomain 9y ago> The last few versions of MacOS have introduced random fires which burn down your .bash_history, leaving this occasional sad, sad result: $ wc -l .bash_history 0 I think there is some context missing here... Why is your .bash_history getting cropped? Was there a change in some default configuration of your Terminal app on update perhaps? On a side-note I really think fish-shell really got history-recall and completion right, which is really the one thing that keeps me using it even if I still script in bash.
- hartator 9y agoWhat do you think about zsh? I really like zsh history.
- jcsalterego 9y agozsh history, from what I've seen a long time ago, can include timestamps, which is why I added a timestamp field in the schema, though it's currently unpopulated: https://github.com/jcsalterego/historian/blob/3bf7158b163d3febca4399a90dd8eb10dcce6611/hist#L38 https://github.com/jcsalterego/historian/blob/3bf7158b163d3f... #soon
- ishigoemon 9y agoBash can as well, though I'm not certain if the OS X version is new enough. http://wiki.bash-hackers.org/syntax/shellvars#histtimeformat http://wiki.bash-hackers.org/syntax/shellvars#histtimeformat
- TheGRS 9y agoIf you're an oh-my-zsh user there is a handy part of the .zshrc config for enabling and customizing the timestamp format. Dead simple.
- sillysaurus3 9y agoI like your zsh history too. Will you post all of it here unedited? Also, on pentests the ~/.bash_history file is literally the first thing we look at. It's lovely: in an instant, you know exactly which files on the system are important, why they're being used, and what the high-priority targets might be for pivoting to a different box. In some cases it cuts hours off the job. So to keep hackers happy, please don't delete your bash history on production servers.
- chongli 9y agoWow, cool! How does this handle the case of multiple shells writing to the history at the same time? I have yet to find a safe way to preserve all that.
- zootboy 9y agoAdd this to your .bashrc: # History stuff. shopt -s histappend export HISTFILESIZE=50000 export HISTSIZE=50000 export HISTCONTROL=ignoreboth export PROMPT_COMMAND='history -a' Individual shells keep their session history in order, while all commands regardless of which shell triggered them get appended to the history file.
- web007 9y ago# infinite history HOSTNAME="$(hostname)" HOSTNAME_SHORT="${HOSTNAME%%.*}" mkdir -p "${HOME}/.history/$(date -u +%Y/%m/)" > /dev/null 2>&1 SESSIONPREFIX=$(date -u +%Y/%m/%d.%H.%M.%S) export HISTFILE="${HOME}/.history/${SESSIONPREFIX}_${HOSTNAME_SHORT}_$$" Only thing you're missing is `HISTFILE`, and an alias like alias histgrep='find ~/.history/ -type f -print0 2>/dev/null | xargs -0 grep --color=auto -InH' https://news.ycombinator.com/item?id=10162189 https://news.ycombinator.com/item?id=10162189 for context
- jesrui 9y agoSame idea with some usage and backup tips: http://jesrui.sdf-eu.org/remember-all-your-bash-history-forever.html http://jesrui.sdf-eu.org/remember-all-your-bash-history-fore...
- 0x09 9y agoLooking at the script, it doesn't write any history itself, it just loads whatever is in the existing .bash_history into its db when `hist import` is invoked (when a new shell is started if you add it to your .profile like the readme recommends.) So this does not do anything to manage different sessions clobbering each others' histories. The solution posted by zootboy will work together with this script however.
- jcsalterego 9y ago
- kalmari 9y agoim on linux but i limit it to 50(user) and auto remove duplicates(system wide). albiet i have read man pages and wiki's to understand and have got into a bit of bash or sh scripting but the things i mentioned are just options.
- visarga 9y agoMy hand made script doing the same thing is also called "hist".
- jcsalterego 9y agoDangit
- purephase 9y agoI love this idea. It's not important for production / env that are managed through tooling, but the "randomish" nature of losing history on dev/stage is one of those, admittedly minor, annoyances that this would solve. Great idea, thanks for sharing.
- kortex 9y agoI use git/gitlab in a private repo to keep track of my zsh profile and history. Stupid like a fox!
- hamandcheese 9y agoI really like how the search feature shows the frequency of each entry. I've thought before it would be cool to see the most used commands of some of the more experienced folks I work with, though ideally it would be slightly more generic than exact commands - i.e. Different arguments would count for the same command.
- jcsalterego 9y agoThe documentation has failed - it's actually just an incrementing ID right now, not a frequency! I should make a clarification soon.
- sluggg 9y agooh... so can I type !id to re-run the command?
- neotek 9y agoApparently not: > hist /youtube-dl 76 youtube-dl --help > !76:p brew install sox
- jcsalterego 9y agoYeah unfortunately it's just an opaque number now, basically.
- hamandcheese 9y agoI just saw numbers and assumed they were frequencies, my bad!
- smike 9y agoI've been using a variant of this: https://debian-administration.org/article/543/Bash_eternal_history https://debian-administration.org/article/543/Bash_eternal_h... which adds all commands to a file ~/.bash_eternal_history Plus a script named "ehist" in my path which contains "cat ~/.bash_eternal_history" -- this enables searches with "ehist | grep git" It also handles the case of multiple shells writing to a history file.
- TheGrassyKnoll 9y agoPretty much what I've been doing.
- gradstudent 9y agoTIL about figlet and cowsay. Thanks HN!
- jcsalterego 9y agoHooray!
- floatboth 9y agoAlso lolcat https://github.com/busyloop/lolcat https://github.com/busyloop/lolcat
- icehawk 9y agoFor anyone wondering, the correct way to do that cowsay command is `figlet moo |cowsay -n`
- jcsalterego 9y agoOH THAT IS AWESOME THANK YOU
- gsylvie 9y agoahem the only correct way to do any cowsay command is to end with double piped "cowsay -n" invocations. $ figlet moo | cowsay -n | cowsay -n ______________________________ / _________________________ \ | / \ | | | _ __ ___ ___ ___ | | | | | '_ ` _ \ / _ \ / _ \ | | | | | | | | | | (_) | (_) | | | | | |_| |_| |_|\___/ \___/ | | | \ / | | ------------------------- | | \ ^__^ | | \ (oo)\_______ | | (__)\ )\/\ | | ||----w | | \ || || / ------------------------------ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
- jcsalterego 9y agoBRAAAAAAHMMM
- pbhjpbhj 9y agos/moo/miaow /down-with-the-kids
- imjustsaying 9y agoI like this. It looks like a much better fleshed out version of a one-off python script I use to search bash history - it even coincidentally has the same name so it'll fit right into the muscle memory :D https://stackoverflow.com/questions/43019250/made-quick-script-to-search-bash-history-how-can-i-make-it-more-robust/ https://stackoverflow.com/questions/43019250/made-quick-scri...
- otterley 9y agoSome sites require the periodic deletion of .bash_history and .history files as a security policy, because they're quite likely to contain passwords and other secrets in them.
- jcsalterego 9y agoPer the README I'm hoping to introduce a scrub command, but yeah -- if you have inline passwords in the commands you run, that's less than great.
- pbhjpbhj 9y agoSounds like something that should be optional in the shell itself, scrub command before writing to history. Naive non-programmers version: use a hash table to censor all substrings of a given length range that match against it ... sounds like it might be expensive (in compute time), also you have to keep a list of those hashes around. Bet it's been wontfix-ed in at least one major shell?
- ams6110 9y agoSee the HISTCONTROL environment variable in bash (and maybe something similar in other shells): HISTCONTROL A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes "ignorespace", lines which begin with a space character are not saved in the history list. [...] This is convenient because any time you don't want a command saved in history, just start it with a leading space. Also look at HISTIGNORE for finer grained control.
- kilroy123 9y agoOdd that your history is being cleared out, it's never happened to me. I always keep my own history of every command I ever run. I've moved this from computer to computer. So I can look back years in the past and see what I've done. case "$TERM" in xterm*|rxvt*) PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"; echo `date +"%b %e %Y %H:%M:%S"` $? \"`history 1|cut -c7-`\" in `pwd` >> ~/.audit' ;; *) ;; esac
- slarrick 9y agoI could never do this. I type my ssh password as a bash command too often. My file would turn out to be a password history!
- fjdlwlv 9y agoUse ssh keys
- jcsalterego 9y agoIs your ssh password `ls`? That's not a great password.
- TheGRS 9y agoI think he means he types it out accidentally, we've all been there. Bonus points for when you're doing it on a screenshare or projector.
- noway421 9y agodidn't even know that's the case, is zsh affected by this mac os bug?
- jcsalterego 9y agoBased on the differences between /etc/bashrc and /etc/zshrc, I don't think so, but I don't know for sure.
- janwillemb 9y agoI'm a programmer and an historian. So the title of this entry gave me a wrong first impression: there are more people like me! I'm not alone! Imagine the disappointment... ;)
- jcsalterego 9y agoThere are more people like you, I bet!
- ianferrel 9y agoThere are dozens of us. Dozens!
- bitdeveloper 9y agoI am one of the dozens. If only I was able to locate a history-related technology job. It seems like you need to be in Washington DC to find anything like that.
- jcsalterego 9y agoI'm quite happy that at least three historian-programmers have come together, here.
- kreetx 9y agoAdd fourth! But I quit the academic path due to economic reasons, i.e bad pay, and needing to apply to grants. I think unless you're explicitly acknowledged as an engineer/programmer it's hard to get anything remotely competitive.
- didsomeonesay 9y agoMy wife is a historian, I'm a programmer. That does not make me the fifth but at least a sympathizer ;)
- SubiculumCode 9y agomy bash history gets deleted whenever I inadvertently type my password and hit enter at the wrong prompt. Type sudo 30 time a day, its gonna happen. Yes I know my history has permissions protection, but still. It is plain text. I don't want to have to look for all the places it get copied too with these solutions.
- SubiculumCode 9y agoand am too lazy to delete that single line. :)
- jcsalterego 9y agoSounds like good security though.
- jlgaddis 9y agoIf this article appeals to you, here's a few little items that you may find handy (cf. bash(1)): $ shopt -s histappend $ export HISTTIMEFORMAT="%F %T: " $ export HISTCONTROL=ignoreboth $ export HISTFILESIZE=-1 $ export HISTSIZE=-1 Also, maybe you should consider backing up ~/.bash_history occasionally?
- jcsalterego 9y ago> Also, maybe you should consider backing up ~/.bash_history occasionally? Oh yes.
- tty7 9y agoWhat are the random fires? please provide an example, i like to control my HISTFILE edit: FIRE == OSX specific
- jcsalterego 9y agoMost recently it seems to happen on a fresh restart. Previously, it had to do with my usage of Terminal; I've had to touch ~/.bash_sessions_disable -- /etc/bashrc_Apple_Terminal has the nitty gritty.
- BhavdeepSethi 9y agoSomething that has been serving me well over the years: export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log; fi' Creates a daily log file of every command entered. Searching for anything is a simple grep command.
- jcsalterego 9y agoNice!
- ball_of_lint 9y agoI do the same thing, and have a couple of commands set up to run grep over the last day, week, month, or ever in my history. I don't use my full history every day, but it's something worth keeping around.
- cbcoutinho 9y agoI'm still new to bash scripting - how do you use this? Just put into ~/.profile and create a cron job for $PROMPT_COMMAND?
- amelius 9y agoJust put it in ~/.bashrc And run mkdir ~/.logs because that's where the logs are stored.
- BhavdeepSethi 9y agoJust add it to your ~/.bash_profile or ~/.bashrc (source it or restart your terminal). PROMPT_COMMAND: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x264.html http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x264.html Nope, no cron. It basically takes your command, and appends (creates if it does not exist) it to a file based on the current date.
- bm1362 9y agoTo preserve your existing prompt, you can append it using +=: export PROMPT_COMMAND+='; if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log; fi'
- alpb 9y agoAlternatively, you can use ZSH and not lose history, even better, have history work simultaneously in multiple terminal windows simultaneously without closing the window to save/read the history of other windows. http://ohmyz.sh/ http://ohmyz.sh/
- jcsalterego 9y agoI think it's more about the MacOS's add-ons to bash here than bash vs zsh -- but who knows!
- justin66 9y agoIs the stuff you linked to needed to realize those benefits in zsh?
- rryan 9y agoNo, just put the following in ~/.zshrc: # share history among terminals setopt share_history # append to the history instead of overwriting setopt append_history # append to history incrementally instead of when the shell exits setopt inc_append_history Look ma, no more lost history!
- zanchey 9y agoHere's a nickel, kid.
- 9y ago
- alister 9y agoWhat an interesting contrast in attitudes toward privacy: He makes an extraordinary effort to maintain his bash history whereas I jump through hoops to delete my history (on logout using a .bash_logout file). I also set my browser to maintain no history, disable saving of chats in everything, delete caches wherever possible, and generally wish that apps and programs had an option to save zero information on exit! If I want "history" beyond a session, I'll explicitly make a shell alias for a command that I want to remember, or make bookmark for a site I want to revisit, etc.
- jcsalterego 9y agoYou should ln -sf /dev/null ~/.bash_history !
- subway 9y agoBetter yet, unset HISTFILE
- pvdebbe 9y agoI see the appeal of this approach. Browser histories are nice in theory because you could search for what you want to revisit, but it never works very well. It'd be better to learn to develop a trigger happy bookmark finger. I still try to keep my site history available, but it's very awkward with the amount of non-family content that I visit. Oh well.
- hendry 9y agoHISTFILE=~/bash_history/$(date +%Y-%m) with h() { grep -a $@ ~/bash_history/* } Work for me... I don't lose bash history. https://github.com/kaihendry/dotfiles/blob/master/.bashrc#L34-L47 https://github.com/kaihendry/dotfiles/blob/master/.bashrc#L3...
- mschuster91 9y agoOn a sidenote, how do I tell bash to immediately commit to history? I often close iterm tabs with cmd-w which seems to make my bash forget to write history.
- jcsalterego 9y agoI think so: http://askubuntu.com/questions/67283/is-it-possible-to-make-writing-to-bash-history-immediate http://askubuntu.com/questions/67283/is-it-possible-to-make-...
- teddyknox 9y agofish
- jcsalterego 9y ago(o)))><
- softwarelimits 9y agoHow can we store history of many users [with screen sessions] on another server - as a simple history keeping and monitoring thing? I looked into auditd but did not like the logging format (maybe there is just a nice web front-end missing that interprets the details) - a simple history would be enough. Next todo was to look if we could send the history to some syslog server - do you have any experiences with a similar solution?
- TorKlingberg 9y agoIt seems like Bash history was made for a time that is long gone, and has not been fixed to work in a modern environment. I have tons of shells open, and I cannot promise to close them carefully and sequentially. Instead I found this to add to my .bashrc: pcmd='if [ "$(id -u)" -ne 0 ]; then echo "$(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log; fi' PROMPT_COMMAND="$PROMPT_COMMAND;$pcmd" It keeps all commands from all open shells in dated log files that I can grep through when Ctrl+R fails me. Just be aware that if someone hacks into your PC they can see every command you have ever run, including any passwords accidentally pasted.
- milosivanovic 9y agoYou can append to .bash_history immediately, and thus make the items available in any other open shells immediately as well. This is supported natively. Search for `shopt -s histappend`.
- TorKlingberg 9y agoI want up arrow to give the last command from that shell though. I'd like Ctrl+R to search all the full history, but I don't think bash can do that combination. Also I just don't trust bash to actually keep my history, no matter what I do with HISTSIZE and HISTFILESIZE.
- gknoy 9y ago`histappend` probaby works the way you want it to. I have about a half dozen terminals open. I want to have the current shell's history seem consistent within any shell, but I want ^R in any NEW terminal to include all the commands entered in any terminal. shopt -s histappend HISTCONTROL=ignoredups:ignorespace # append to bash history Right Now export PROMPT_COMMAND="history -a" I share your distrust, though -- I've frequently lost my bash history for $REASONS (which another comment here seems to have answered :)) -- but the convenience of not having my shell history clobbered by which-shell-I-close-first is _amazing_.
- marklgr 9y ago
- l0b0 9y agoI've been curating my .bash_history for years; it's a great way to recall all those contorted commands which come in handy every year or so: https://github.com/l0b0/tilde/blob/master/.bash_history https://github.com/l0b0/tilde/blob/master/.bash_history Git GUI plus a simple Makefile target to sort it is all the tooling necessary: https://github.com/l0b0/tilde/blob/b16794f2ff209a6bc64813f0218168cca34e603f/Makefile#L94 https://github.com/l0b0/tilde/blob/b16794f2ff209a6bc64813f02...
- monsieurbanana 9y agoHoly guacamole. You madman, you put your whole bash_history on a public github? If someone put a gun on me and asked to give him my bash history, I'll probably do it but not before thinking twice. I've also kept my bash history (well, more like my zsh history actually) for a few years and across a few re-installs now. I'm sure there's a few cleartext passwords in there (for nothing too important), a couple of dubious wget commands, all the videos I've ever watched (I use a CLI video player) and who knows what else. Oh and a bunch of confidential work stuff, I'm sure. Now that I think about it, maybe I should delete it...
- gknoy 9y agoThat was my initial thought as well, but looking at it, it seems like he really takes the time to _curate_ it: rsync --rsh='ssh -p 2020 -i ~/.ssh/host.pem' --archive --human-readable --progress --verbose host:/path /target # network transfer In examples like the above, he appears to have sanitized things to be useful from the perspective of "How do I do X again?" -- very cool.
- makefu 9y agoFor me, the *_history is a deeply personal thing as it shows how i work and how i changed my working over the years. I think you are very brave to make this document available to the world - it is not something i would like to do. EDIT: I think of it like the browser history for your daily work. EDIT 2: It seems quite a lot of people think it is a good idea to store their bash_history on github, who knew! google dork: "inurl:github.com intitle:bash_history"
- nikcub 9y agoWhen I was first programming and into UNIX it was the norm amongst those I was learning from that you'd symlink your history file to /dev/null This had a few advantages which might not be immediately apparent. The most obvious is that you remove the risk of leaking private or sensitive data. The second is that searching your history is an anti-pattern. If there is a command you can't remember, or if there is a group of commands you need to accomplish a task, you should be writing shell scripts My ~/bin folder has 104 files in it[0] and is in git, is available wherever I log in, whichever tty I have open and has a much better taxonomy than 'search for part of command' based on doing tasks. The same can't be said for history files. [0] at its peak when I was a BSD and RHEL user it would have been more files but i've recently switched to Alpine.
- pvaldes 9y agoThe problem with history is that records all your activity and is a big snitch. On the other hand you will not want to save in your database repeated or trivial commands like "ls ." normally. You can have the best of both worlds if you configure its behaviour in bash. Any command that starts with a space is still successful but will be discarded in bash history. As "internet is for porn" could be useful to delete any video viewer entry automatically. (Add some lines like: "alias vlc=' vlc'" in your .bashrc). History can be also configured to save only one copy of duplicated commands. If you have a sensible or difficult to memorize command the best is to put it in a script, not in a db.
- __david__ 9y agoI like that as a concept, except it doesn't even go into local history (up arrow), which makes the feature so frustrating for me that I ended up turning it off. Too many times I copy and paste something and end up with a little extra whitespace at the beginning. I guess the number of times I've done it on purpose was dwarfed by the number of times I did it on accident, and that killed it for me.
- alphapapa 9y agoTo a point you have a point, but there is a point at which your ~/bin becomes unwieldy. I have 386 commands in mine, and for commands I don't use very often, I tend to forget their names, or that they even exist. So searching my fish history with Percol can be much faster than trying to remember the specific, hyphenated name I gave to the script I wrote a year ago. I also have a `~/.savedcommands` file that I save one-liners to with a comment at the end, and `C-s` at the prompt loads that file into Percol, so I can search these more easily than searching the entire shell history. `savelastcommand` saves the last command to this file, or `savecommand COMMAND` does the same thing.
- yason 9y agoI've gradually come up with a way too elaborate system for maintaining and sharing bash histories locally. I run tmux with several long-running bash prompts and not only I want to append each shell's history into a log incrementally but also to share history between the running shells. I have a function as my prompt command that does: - dump the current in-memory history into a separate logfile every few minutes timestamped (using HISTTIMEFORMAT) - clear the local in-memory history and reload in-memory history from unique history lines from all stored log files, using the most recent timestamp on each Once there are more than N log files, one of the shells does a similar uniquefying compation step for N log files and writes the output into one new log file. It uses 'mv' to do the compation atomically by moving the affected log files away into a temporary directory for compaction. If other shells were to update their logs during the compaction those additions would just be saved as normal and compacted in the next cycle. There are always duplicate history lines in the logs to keep things fast so there's no chance for a race condition: no command line in the history can get accidentally deleted and any duplicates are just removed during reading. As a final step I atomically copy the latest compacted history into .bash_history as a backup. The real data lives in my logs anyway but a single .bash_history is easier to backup: it might be a few lines short but it's always mostly up-to-date. Looking back at this, I reckon the current Bash history implementation surely can't be ideal.
- jlebrech 9y agoctrl-r is great, but i'd like to also delete unwanted results and favourite some and label them.
- larkery 9y agoFor those on zsh I have something similar [1-2]. It hooks to zshaddhistory and stores the command, running time, CWD, hostname and exit status in a sqlite database, and provides a simple query command. With a git merge driver [3] the history database can be kept in source control and shared between hosts. Queries look a bit like $ histdb blah time ses dir cmd 09/02 24 ~ ogr2ogr temp/blah.shp 'WFS:http://environment.data.gov.uk/ds/wfs?SERVICE=WFS&INTERFACE=ENVIRONMENTWFS&VERSION=1.0.0&LC=3000000000000000000000000000000' 09/02 24 ~/temp cd blah.shp 15/02 146 ~/.emacs.d git commit -am "blah" 22/02 175 ~ test="asdf/blah.shp" 09:48 743 ~/.histdb hist blah The sess column here is a unique (per-host) session number which means it can recreate any transcript with a suitable query; if I ran histdb -s 24 it would produce the whole session containing the top two results above, including directory history. [1] https://github.com/larkery/zsh/blob/master/sqlite-history.zsh https://github.com/larkery/zsh/blob/master/sqlite-history.zs... [2] https://github.com/larkery/zsh/blob/master/self-insert-override.zsh https://github.com/larkery/zsh/blob/master/self-insert-overr... [3] https://github.com/larkery/zsh/blob/master/histdb-merge.zsh https://github.com/larkery/zsh/blob/master/histdb-merge.zsh
- dmix 9y agoLooks good. You should separate this into another repo with a README. I use zgen [1], a package manager with ZSH which lets you add libraries via github repos. That way I can keep it up-to-date without manually checking in on the project. Also your [3] link is broken. https://github.com/tarjoilija/zgen https://github.com/tarjoilija/zgen Edit: any way to import the existing .zsh_history?
- larkery 9y agoIt appears I am outside the edit window, but [3] should be https://github.com/larkery/zsh/blob/master/histdb-merge https://github.com/larkery/zsh/blob/master/histdb-merge (no .zsh). Thanks for pointing that out. I don't use a zsh package manager and don't really want to learn one, but if you can tell me the minimal glue I need to add to make these files into a package I will happily duplicate them into another repository and keep them up to date there. Ed.: https://github.com/larkery/zsh-histdb https://github.com/larkery/zsh-histdb I haven't done anything to import the history file because some of the information is missing so it would be a bit untidy. You could do something like history 0 | while read -r num line; do zshaddhistory "$line" done This will make bogus entries where the history includes newlines; you could probably use a loop on history number instead, or do something in the while loop to accumulate split lines by looking at "$num" and seeing if it goes up.
- joelthelion 9y agoI think a lot of the problems linked to bash history could be solved elegantly by the use of a daemon to exchange information between concurrently opened shells.
- vfclists 9y agoAre there any bash history systems which also store the directory the command was issued in?
- djKianoosh 9y agoI actually keep a bash history per directory. it really helps when i reopen a project folder after a few weeks or months. lets me know generally what I was doing. https://gist.github.com/leipzig/1651133 https://gist.github.com/leipzig/1651133
- saurik 9y agohttps://news.ycombinator.com/item?id=10695305 https://news.ycombinator.com/item?id=10695305 ^ In this comment I explained how I just have all my bash history logged directly into SQLite.
- red023 9y agoIf you touch ZSH (oh my zsh, if that makes a difference) once you will never ever want to use bash again.
- jcsalterego 9y agoI've tried zsh many times and it's not for me :'(
- jwigg 9y agoAlternatives to this implementation: https://github.com/barabo/advanced-shell-history https://github.com/barabo/advanced-shell-history https://github.com/tkf/rash https://github.com/tkf/rash both are fairly featureful and capture additional metadata about the commands run it is also possible to use similar tools to log your bash history to mysql, or to syslog, which may be preferable for auditing purposes.
- saulgausin 9y agoI think this is nice. I use tmux every day and this will help me to keep my bash history in my multiple tabs.
- mcguire 9y ago"In its nascent form, a script backs up your .bash_history into a SQLite database that sits in your home directory as well."
- fritzo 9y agoI wish there were a tool to share .bash_history across an organization. This would make onboarding so much easier. It would also help to disseminate shell tricks.
- kisil_reboot 9y agoI've seen a lot of teams keep a shared scripts/aliases file, and import it to everyone's .bashrc or equivalent. Very useful.
- andmarios 9y agoShameless plug, my version of YABHA (yet another bash history app): https://github.com/andmarios/bashistdb https://github.com/andmarios/bashistdb Written in go, uses sqlite and can work locally or remotely. In the latter case you can send history from many accounts and search globally. Transport encryption is based on NaCl. One binary serves all roles. Doesn't store other information than command line and time but this is what I need most of time. The main pain point behind its creation was searching in history. There is a global flag (search in all accounts, -g), the wild card is SQL's wild card (%). Less frequently used but very helpful, content search (-A, -B, -C, like grep). Also regexp is supported though very rarely is needed.
- inetknght 9y agotbqh, I would like to see regexp be default in more situations. It's handy and important to learn for personal growth and setting it as a default would passive-aggressively try to encourage more novices to learn it.
- andmarios 9y agoRegexp search is slower. SQLite's support for regexp comes from an external library (sqlite3-pcre) that most of the time isn't installed on the host system. Even when it is, it doesn't always work. My solution around this, is, when regexp is enabled, to query for all the history and then have Go perform the regexp search itself —the normal is to let SQLite perform the search. Depending on your CPU and history size, you may need a couple seconds for the result. For example when the server process runs on an Atom processor and the history is about 150.000 lines long, a regexp search takes about 7 seconds. A normal search with a wildcard on the same machine and history database, needs only 1 second.
- inetknght 9y agoIf it's slower, then use a simpler query or come up with a way to improve the back-end search speed (which you did, it looks like). My point is that novice developers don't usually work with that size of data. And if they are working with that size of data, then both regex and performance are good things for them to learn :)
- rbc 9y agoI use my shell history to pickup past command invocations, but at some point, you have to clean things up and create a script. The script could be for repetitive tasks or help tame complicated command line syntax. The nmap, curl and groff utilities are a few of my favorite examples of commands that have too many options.
- deleted 9y ago[deleted]
- blincoln 9y agoAs a pen tester who frequently finds passwords and other sensitive data in shell history files[1], I fully support this effort to make my job even easier :). [1] Either inline in mysql-type commands, or when users accidentally paste/type their password in when the system isn't expecting it.
- andai 9y agoHow do you find passwords in a long history file?
- ams6110 9y agoI only save about 40 lines of shell history. If I find myself repeating something I make a script or alias. Root account never saves history.