Working Fast
The keystrokes, history tricks and chaining that make experienced people look fast.
Updated
Keystrokes
- Keyboard Shortcuts at the Prompt (Apprentice): Ctrl+A and Ctrl+E jump to the start and end of the command line, Alt+B and Alt+F move a word at a time, Ctrl+W and Ctrl+U delete a word or the line, and Alt+. brings back the last command's last argument.
- History Tricks: !!, !$ and Ctrl+R (Journeyman): !! runs the last command again and !$ reuses its last argument, sudo !! repeats a command that needed sudo, Ctrl+R steps back through older matches, and four lines in ~/.bashrc keep a longer history that every terminal adds to.
- Jumping Around: cd -, pushd and ** (Journeyman): cd - switches between two folders, pushd and popd keep a stack of folders to come back to, ** reaches into every folder below once globstar is on, and CDPATH lets cd find a project's folders from anywhere.
Chaining
- Did It Work? Exit Codes, && and || (Apprentice): Every command ends with an exit code, 0 when it worked and another number when it didn't, which $? shows; && runs the next command only if the last one worked, || only if it failed, and ; either way.
Exercise: Fewer Keystrokes
- Exercise: Fewer Keystrokes (Journeyman): Write the settings that make your shell faster into a file of your own, count a photo project's photos four folders deep with **, read two exit codes, and write one line that backs up the beach photos and says so only if it worked, then let a check script tell you what's done.