Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Better yet, just set your history to 10k-20k+ items and use reverse-search (ie. Ctrl+r in bash) to recall your old commands. Navigation aside, about 80-90% of commands I use regularly are already in the shell history.


sort by: page size:

I do this a lot as well. A useful side-tip to go with that: set your bash history size to be unlimited (or at least really big) to avoid losing less frequently used commands.

Set a huge number for your shell history and dedup. You’ll effectively save every command you ever typed in chronological order. You can even append comments to the end of the command for your future self.

Then, fzf your history.


I find with CLI there is much less to remember over time due to command history. If I ever ran the command in the past, I can see exactly what I ran. I don't have to remember as the computer does it for me. The only possible tweak this involves is upping your history, as many shells default to a short history.

I have a shell history with the limit of 1M lines, and shells append to it, not overwrite it on exit.

I never have to review (except occasional grep something ~/.zsh_history), but I find myself typing Ctrl-R to find commands in history all the time.


I‘ve been doing this ever since I migrated from Windows to Mac in 2015. My bash history has over 40k lines, datestamped. I can recall any command I have typed in my terminal in the past seven years. Extremely helpful whenever I need to repeat anything in the terminal.

# Edit

I sometimes add comments to commands via `# This‘ll do this and that` so that I can find the command by those keywords in the bash history.


I tend to forget aliases I've set up and mostly use Ctrl+R to reverse search history and find the command I want if I've used it before. Either that or "history | grep <command_used_before>" if it was some time in the past. Aliases just don't stick in my memory.

Bash can do that, with Ctrl-r. Press Ctrl-r, then type beginning of command, then press Ctrl-r repeatedly to go back through history.

https://www.digitalocean.com/community/tutorials/how-to-use-...

That page also deals with stuff like getting bash not to delete history with each session, so searching history can be more useful.


I'm up to about 4 years of history at this point. I use a dumb bash hook that sorts and reloads the history on each command execution, and yes, it's getting a little slow. I wish I could do this through some daemon-based DB-backed system but this works for now. Maybe I'll switch to zsh when it gets too slow.

The reason I have the hook reload and sort on each command is so that I can use a dozen screen sessions at once and:

1) they don't overwrite each other's history

2) each session's history is instantly searchable to the others

3) sorting is useful because each session prepends a session ID to the commands, so that Ctrl-R backward search can always hit the current session's commands first. And I can reboot/restart screen and recover history in each session.

(edit: I looked at the zsh-db project the other poster linked, and this does pretty much the same thing just probably slower since there is no DB involved).


When first stumbling my way around the shell, after learning about tab completion I discovered the magic wizardry that is command reverse/history lookup (cntrl-r start typing command ... see last command you entered that matches)

This sounds quite awesome, it's a pity that the realization is quite 'alien' to unix way of things. IMO shell commands history should be a database by default, not just a single file that gets auto-appended with both awesome commands and crap you don't really want to get stored for later.

Thanks for linking this project, will try it, it may be a game changer.


If you put this in your `~/.inputrc` [1]:

    "\e[A": history-search-backward
    "\e[B": history-search-forward
    "\e[C": forward-char
    "\e[D": backward-char
  
you can start typing a previous command and go up through your history for all commands starting with whatever you currently have typed into the bash shell. Reset the scrolling through the history with `ctrl+c`.

Personally, I hate that powershell remembers your position in the shell history. I don't want to maintain a mental model of the shell history rollodex and where I am in it. That's one less part of my brain that I can't use for thinking about the code. If I have a set of commands to type over and over:

    history 20 | head -10 | sed -r 's/^ *[0-9]+ *//g;' > new_script.bash

* [1] http://codeinthehole.com/writing/the-most-important-command-...

Good tool, but my history is so noisy I had to find another way. Lately I started to add a new habit in my shell actions.

When a command has some cognitive requirements I create a script with some ${1:-default} values and I store them all in $PATH enabled local/bin

All my scripts start with __ and then some capital letters indicating the topic.

I can copy them to new machines, which is something I would not do with my history.


I keep all bash history, automatically appending it to a file that’s backed up in google drive. That deals very effectively with remembering how I did something from the command line in the past, which is being mentioned in this thread. However it doesn’t work for commands issued on a machine which isn’t your main personal machine.

Yep, zsh, and most likely fish and other shells manage to keep all your commands in the history, no matter how many sessions you open.

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 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.

I keep some as shell aliases, shell scripts or Git aliases, but mostly I just use my shell history, finding commands with Ctrl+R and a few characters that I know to be in there somewhere. (If you want to do this, make sure you set its limit high enough so you don’t lose stuff.)

I use an eternal history setup for bash, with bash session tags that let me sort history by tag for correct backward-search behavior.

(edit) Not to imply this functionality belongs to a terminal, far from it. But it's nice to have access to 2 years of shell commands :-)


(I have a feeling that) my frequently used commands change depending on what I'm doing, and with time. Instead of trying to alias my current favourite commands, I tend to just use the backwards history search built in to my shell, and access it with Ctrl-R. I can type the beginning of the command and have the rest of it completed for me.

The only thing that would make it better is Ido-style completion.

next

Legal | privacy