What is your single most favorite command-line trick using Bash? [closed]
We all know how to use <ctrl>-R
to reverse search through history, but did you know you can use <ctrl>-S
to forward search if you set stty stop ""
? Also, have you ever tried running bind -p to see all of your keyboard shortcuts listed? There are over 455 on Mac OS X by default.
What is your single most favorite obscure trick, keyboard shortcut or shopt configuration using bash?
Solution 1:
Renaming/moving files with suffixes quickly:cp /home/foo/realllylongname.cpp{,-old}
This expands to:cp /home/foo/realllylongname.cpp /home/foo/realllylongname.cpp-old
Solution 2:
cd -
It's the command-line equivalent of the back button (takes you to the previous directory you were in).
Solution 3:
Another favorite:
!!
Repeats your last command. Most useful in the form:
sudo !!
Solution 4:
My favorite is '^string^string2' which takes the last command, replaces string with string2 and executes it
$ ehco foo bar baz
bash: ehco: command not found
$ ^ehco^echo
foo bar baz
Bash command line history guide