This isn’t so much a blog post, as it it a note. I’ll probably be updating this list in the future with more shortcuts as I discover them.

#1 - Last command shortcut

The string !! expands to the entirety of the last command run. Forgot sudo on a command? no problem, just type sudo !!

#2 - Last argument of the last command

The variable $_ is set to the last argument of the last command run. Very useful if doing lots of stuff with the same file.

#3 - Search the history

!gcc will expand to the last command that starts with gcc. If you’re more visual, CTRL+r is your friend. type to search.

#4 - Beginning of the line

CTRL+a - Jump to the beginning of the line

#5 - Clear the screen

CTRL+l - Much quicker than typing clear

#6 - Quick replace

Replace “emacs” from the last command with “vi”, type ^emacs^vi^

#7 - Quick Exit

CTRL+d - just like typing “exit”, but much faster.

#8 - Pipe into “while read line”

This lets you execute a series of commands for each line of text that’s piped in, via read and a for loop:

cat file.txt | while read line; do echo "$line"; done

Also, we can change the delimeter that read uses with the -d flag.