CLI Efficiency: Common Basics

I like the command line. I like the keyboard.  For me it’s all about the efficiency: if done right, it’s just faster & easier to use the keyboard to tell the computer what to do than it is to use the mouse to show it. (Yes, there are exceptions – it’s usually easier to do graphics work with a mouse, for example.)

The first time I ever got really excited on a computer was when someone started showing me all of the keyboard shortcuts available at the time. I immediately found myself substantially more productive, and that productivity just fueled a desire to learn even more shortcuts, more tips and tricks, and to find the most efficient way to do whatever it is I needed to do on the computer.

While there are many different keyboard shortcuts available, depending on the application or the shell, there are also many similar ones. Even an unintuitive interface or standard is useful when it is common: learn once and use (almost) everywhere. One of those standards is the line-editing functionality most often implemented using the GNU Readline library or one of its functional (but differently licensed) equivalents like Haskeline, Editline, vrl, or others. In a nutshell: these libraries provide a common user interface for interacting with a command line and editing its contents using special keystrokes or key combinations. In what may be no surprise to those familiar with GNU, these key combinations are very reminiscent of Emacs and tend to utilize the Control key extensively.

Readline actually dates back to 1987 and either it or one of its equivalents has been available for most of the vast number of command line shells ever since. This is true for both general purpose operating systems like Linux and Mac OS X (both of which include the Bash shell which uses Readline), or for purpose-specific or embedded operating systems like VMware’s ESXi (with its Busybox shell), Cisco’s NX-OS, NetApp’s Data ONTAP, or many others. Once you become familiar with the basics of these keystrokes, you’ll be able to be more efficient in virtually any CLI environment (with the notable exception of Windows, although there is a project even for that – WinEditLine).

Note: the list below is not all-encompassing, but includes the key combinations that appear to be supported consistently across platforms. There are other key combinations that work on one or more platforms but not on others; a future post will provide more detailed comparisons for these other key combinations.


Keystroke Action
Ctrl+a Move to the beginning of the line
Ctrl+e Move to the end of the line
Ctrl+b Move to the left (back) one character
Ctrl+f Move to the right (forward) one character
Esc-b Move to the left (back) one word
Esc-f Move to the right (forward) one word
Ctrl+p Display previous command (in history buffer)
Ctrl+n Display next command (in history buffer)


Keystroke Action
Ctrl+d Delete the character under the cursor
Ctrl+w Delete the word to the left of the cursor
Ctrl+k Delete all characters from the cursor to the end of the line
Ctrl+u Delete all characters from the cursor to the beginning of the line

3 thoughts on “CLI Efficiency: Common Basics

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s