Blog

CuTt2: Useful terminal shortcuts I

Copper’s Tips & Tricks #2: Useful terminal shortcuts

If you didn’t know about this (and some people at the office don’t/didn’t), first of all, I feel bad for you, your brain, and your fingers. Specially your fingers. By pressing Cmd+R and starting typing, the terminal will start to look for sent commands that match the text you’re entering. By pressing Cmd+R again, you can cycle back through them (doesn’t loop however, so it runs out of matches eventually). So woo! There you go.

Now, for those newly educated and those who already knew about it, I should tell you that the command history is very, very small, to the point that it bothers the heck outta me whenever I’m ssh’ing into other servers which don’t have these improved settings. We use supercomputers nowadays, but some configs are more fitting for the day old ones. In this case we’re talking about Ctrl+R, that lovely lovely thing that prevents our fingers from falling off from having to type things way too much and our minds from melting inside our headbrains from having to remember all the things to type way too much.

First of all, the history of commands can get bloated very quickly due to duplicate commands. Thaaat should get fixed:

# Don't put duplicate lines in the history
# Erase duplicate lines in the history
# Don't add commands that start with space to the history
#   Why? ...no idea? But sounds useful...? Maybe?
HISTCONTROL=ignoredups:erasedups:ignorespace

Second of all, if you use multiple sessions, the history gets effed up due to… humans overlooking the obviously superior option? Anyway, appending to the history file is way better than just overwriting it, so here:

# append to the history file, don't overwrite it
shopt -s histappend

Lastly, commands are TEXT. We can fit A LOT of text on our disks, and our CPUs and SSDs can handle looking through a couple million lines of text rather quickly. Increase that history size and file size to infinity! Or just a large number. Like, say, 10 million. I don’t think you’ll type 10 million different commands on a single machine, but if you do, boy do I give a hats off to you:

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000000
HISTFILESIZE=200000

Here’s all together for the tldr;, for the lazy and time efficient people:

# Don't put duplicate lines in the history
# Erase duplicate lines in the history
# Don't add commands that start with space to the history
#   Why? ...no idea? But sounds useful...? Maybe?
HISTCONTROL=ignoredups:erasedups:ignorespace

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000000
HISTFILESIZE=200000

Leave a Comment