Command Line Tips (part I: simple key bindings) 1
Working on the command line can seem daunting and slow. With a few handy tips working on the command line can be productive and efficient.
This entry is the first of a few to cover some of the command line techniques I use to be more productive on the command line.
Before we get started, there are two things I should cover.
- It’s all bash/ sh. Other shells are great, but I don’t know them. Bash is pretty much the default in Linux distros these days, which is probably why I wound up learning it.
- This is geared toward the beginner, and is aimed at interactive use as opposed to programming.
- [ctrl] commands are a simultaenous press. Press both keys at the same time.
- [esq] commands require that you press escape, then let off, then press the next key.
The most general key bindings used in bash are for history navigation and command editing. The ones I commonly use are:
| [arrow up] or [ctrl]-p | Move back in command history |
| [arrow down] or [ctrl]-n | Move forward in command history |
| [ctrl]-a | move cursor to begining of line |
| [ctrl]-e | move cursor to end of line |
| [ctrl]-k | erase to end of line |
| [esq]-b | skip back one word |
| [esq]-f | skip forward one word |
| [esq]-d | erase word to right of cursor |
| [ctrl]-r | backward history search* |
The [ctrl]-r requires some explanation.
When you hit [ctrl]-r, you are in a history search mode, typing further characters performs an auto-complete style search of your command history.
By typing ‘if’ at this prompt, I find that I have a match ’/sbin/ifconfig -a’, which I’d recently executed.
(reverse-i-search)`': (reverse-i-search)`if': /sbin/ifconfig -a
Pressing enter then executes the command. Other keys like cursor navigation will bring you back to regular command prompt mode, and allow you to edit the command.
Good luck and have fun!
Trackbacks
Use the following link to trackback from your own site:
http://blog.kineticweb.com/articles/trackback/48
Comments
-
This is a great list! Thanks, Andy. When I first learned a few of these a month or two ago, my command-line productivity skyrocketed!!
