protips - asottile/scratch GitHub Wiki

game changers that I wish I knew earlier

bash: ^r

reverse search for a command that was previously typed in the history

type ^r again to search past the current match

bash: fc

"fix command": open the previously typed command in a text editor so you can fix it up

bash: ^xe

Like fc, but type ^xe while typing a command to edit it in an editor. note that it must be typed in one chord (like emacs)

If you want to use your favorite editor with fc, set one of the following environment variables: Bash attempts to invoke $VISUAL, $EDITOR, and emacs as the editor, in that order. (from man bash) To cancel the execution of the command while in the editor, you should exit it with a non-zero code or delete the command text.

bash: !!

A substitution which contains the previous command, some useful invocations:

$ ls /proc/1/exe
ls: cannot access '/proc/1/exe': Permission denied
$ sudo !!
sudo ls /proc/1/exe
/proc/1/exe

$ ls /tmp/ | grep sys
systemd-private-e21be514f23449189063b6bd95ec13ef-bolt.service-MCMIaN
systemd-private-e21be514f23449189063b6bd95ec13ef-colord.service-yNWr06
systemd-private-e21be514f23449189063b6bd95ec13ef-fwupd.service-geozA1
systemd-private-e21be514f23449189063b6bd95ec13ef-iio-sensor-proxy.service-YcZF0S
systemd-private-e21be514f23449189063b6bd95ec13ef-rtkit-daemon.service-ehxeOd
systemd-private-e21be514f23449189063b6bd95ec13ef-systemd-timesyncd.service-CGGtoI
$ watch "!!"
watch "ls /tmp/ | grep sys"
(opens up watch panel)

bash: !$

A substitution which contains the last segment of the previous command

example usage:

$ $EDITOR test.py
$ python !$
python test.py
Hello world!

bash: ^v

^v followed by a key press will produce that key literally. Useful if you want to grep for a tab character or something:

$ (use the actual key presses)
$ grep -l -r '^v[tab]' .
./Makefile

bash: ^\: more powerful than ^C

^\ sends SIGQUIT (default behaviour: terminate + produce a core dump) which can be useful to kill things that normally catch ^C (SIGINT).

github: [y]

pressing [y] on a github page will give you a permalink

ssh: [enter]~.

When an ssh session is stuck, you can type this combination and it will disconnect. ~? shows the other things ssh recognizes but I don't think they're that useful

bash: ctrl+shift+u

this allows you to type a unicode code point on the terminal more easily

so for example this key sequence: ctrl+shift+u 2603 enter will give you

⚠️ **GitHub.com Fallback** ⚠️