brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Alt-b and Alt-f move through a shell command one word at a time

Shell
~/tips/tip-shell-alt-b-alt-f-word-jumps

Alt-b back one word

Jump over words on the command line instead of holding the arrow keys.

Holding the left arrow to get to a typo in the middle of a long command is slow. Readline, the line editor in bash, can jump by words.

These work in bash out of the box, and in zsh with its default emacs keys too:

Alt-b    back one word
Alt-f    forward one word
Alt-d    delete from the cursor to the end of the word
Ctrl-a   start of the line
Ctrl-e   end of the line

Say you typed rsync -av /srv/media/photos/ backup:/data/photos and want to change media. Ctrl-a and a few presses of Alt-f get you there, Alt-d removes the word and you type the new one.

A word here means letters and digits, so slashes, dots and dashes count as breaks. That makes Alt-b stop at each part of a path, which I find just right for editing paths.

On a Mac the Option key does not act as Alt by default. In Terminal, turn on Use Option as Meta key in the profile settings, and in iTerm2 set Option to send Esc+. Without that, press Esc and then the letter, which does the same thing and also works over any SSH session.

Further reading: Bash manual: Commands For Moving

More Shell tips zmv -n '(*).log' '$1.txt' zoxide query -ls project f=$(mktemp --suffix=.json) shopt globskipdots echo $EPOCHSECONDS All Shell tips (78) All topics

Link