You can use the arrow keys on keyboard to move around in the command line. Bash also provides convenient keyboard short cuts to navigate effectively. Try them out and see for yourself.
To become a Bash pro user you have to get yourself familiar with the keyboard shortcuts. Once you do, you'll find yourself productive.
| CTRL+b | move backward one character |
| CTRL+f | move forward one character |
| ESC+b | move one word backward |
| ESC+f | move one word forward |
| CTRL+a | move to beginning of line |
| CTRL+e | move to end of line |
| CTRL+p | move to previous line |
| CTRL+n | move to next line |
| ESC+< | move to first line of history list |
| ESC+> | move to last line of history list |
Moving around words using ESC+f and ESC+b are my favourites in this list. Jumping to first and last lines of the history list is also useful.
Bash provides convenient keyboard short cuts for deleting and retrieving the last deleted item.
| CTRL+d | delete one character forward |
| ESC+d | delete one word forward |
| CTRL+k | delete forward to end of line |
| CTRL+u | delete the line from the beginning to point |
| CTRL+y | retrieve last item deleted |
| CTRL+r | search backward |
When you hit CTRL+r the prompt change to
(reverse-i-search)`':
Type the first few characters of the command you have entered before, Bash completes the command line for you.
| ESC+c | Capitalize word after point |
| ESC+u | Change word after point to all capital letters |
| ESC+l | Change word after point to all lowercase letters |
This is especially useful, when your caps lock is accidentally on and you type something without realizing it. Without the short cut to change case, you would turn caps lock off, delete the characters you accidentally typed in upper case and then type them again. Now you are empowered with ESC+l.
Miscellaneous
| CTRL+l | clear screen |
| CTRL+d | logout or close the terminal window |
| CTRL+c | cancel the currently running program or command |
Spend some time with these keyboard short cuts. Become a productive Bash user.
Readline shortcuts
Many of the editing shortcuts you've mentioned are provided by readline and are common for many GNU programs. They are by default the Emacs keys. You can do a `set -o vi` to make it use vi keystrokes instead.
thanks for the tip
Exactly.
I love when the same keystrokes work in MySQL console, PostgreSQL console, Python interpretor and many other programs.
And don't forget repetition
ESC+ repeats the next letter or command (digit) times.
If you have your caps lock key remapped, and you want to upper-case a variable name with underscores or something, you can capitalize the entire thing with 4 keystrokes. If my variable was typed as my_funky_constant, and I need that in all upper case, and I am on the first character, I can simply type 3u .
Damnit, that screwed up my entry
that's ESC+3+ESC+u
I tried to put angle brackets in my post, and that didn't work.
Post new comment