Linux

Use keyboard shortcuts at the command line

The bash shell gives you flexibility at the command line for editing. Have a look at these examples.

Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

The bash shell offers a lot of power for interacting with the command line. By default, the shell uses an Emacs-like mode to edit lines, which you can change to a vi-like mode. The mode you choose largely depends on which editor you're most comfortable with.

For example, when using the default Emacs-like mode, you can use a number of [Ctrl] or [Esc] key combinations to navigate and manipulate text when you're working on a lengthy command. Here's a list of some of your options:

  • Press [Ctrl]B to move backward one character.
  • Press [Ctrl]F to move forward one character.
  • Press [Esc]B to move one word backward.
  • Press [Esc]F to move one word forward.
  • Press [Ctrl]A to move to the first character in the line.
  • Press [Ctrl]E to move to the end of the line.
  • Press [Ctrl]U to delete the current line.
  • Press [Ctrl]K to delete from the cursor's current position to the end of the line.

You can also use a command to search through your history. Press [Ctrl]R to perform a reverse search through your history for a given command. When you've located the command, press [Enter] to reexecute it, or edit the command to change it.

If you frequently work from the command line, using these shortcuts can save you a lot of time.

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

0 comments

Editor's Picks