On TV.com: THE GIRLS NEXT DOOR photos

Keyboard shortcuts in bash and zsh

Tags: Vincent Danen, keyboard, keyboard shortcut, Ctrl, current line, cursor, Alt, shell, Linux Tips Newsletter

  • Save
  • Print
  • Recommend
  • 3

Takeaway: Learn these timesaving keyboard shortcuts for working in the bash and zsh shells.

The bash and zsh shells are very similar, with zsh being more of a "power-house" shell than bash. Key commands for both shells are similar and knowing these time-saving shortcuts can be a great boon for those using the shell often. Most of these commands are used for quick navigation or editing of the current command line.

To move to the beginning of the current line, use [Ctrl][A]. To move to the end of the current line, use [Ctrl[E]. To move the cursor forward one word on the current line, use [Alt][F]; to move the cursor backwards one word on the current line, use [Alt][B].

You can also use key commands to do more than move around on the current line. They can be used to manipulate text on the current line as well. For instance, use [Ctrl][U] to clear the characters on the line before the current cursor position and [Ctrl][K] to clear the characters on the line after the current cursor position. Bash and zsh work slightly different here. In zsh, [Ctrl][U] clears the entire line instead.

To delete the word in front of the cursor, use [Ctrl][W]. To delete the word after the cursor, use [Alt][D].

You can also search history quickly using [Ctrl][R]. In bash, you'll be given a prompt:

(reverse-i-search)`':

You'll see this in zsh:

bck-i-search:

Type what you'd like to search for, such as ssh, and you'll get the first matching entry in the history. Continue pressing [Ctrl][R] to search further back in the history for all entries that contain ssh. When you find the one you want, press [Enter]. If you need to modify a command that you find, use the right arrow to break out of the search and make the changes you need.

Shortcuts can be used to change the case of words as well. To make the current word after the cursor uppercase, use [Alt][U]. To make it lowercase, use [Alt][L]. Note that cursor position here is important, if the cursor is midway in the word, only the part of the word after the cursor will have the case changed. To capitalize a word, use [Alt][C] (this is also cursor-position-dependent; if the cursor is midway in a word, that letter will be capitalized).

Keyboard shortcuts save steps and knowing these few shortcuts when working on the command-line can save a lot of time and typing.

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!

  • Save
  • Print
  • Recommend
  • 3

Print/View all Posts Comments on this article

Even though I prefer the most basic of shells, good help pointsDanLM  | 04/27/07
Good suggestionsvdanen  | 05/07/07
bash learned from Emacsthommym@...  | 05/01/07

What do you think?

Article Categories

Security
Security Solutions, IT Locksmith
Networking and Communications
E-mail Administration NetNote, Cisco Routers and Switches
CIO and IT Management
Project Management, CIO Issues, Strategies that Scale
Desktops, Laptops & OS
Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
Data Management
Oracle, SQL Server
Servers
Windows NT, Linux NetNote, Windows Server 2003
Career Development
Geek Trivia
Software/Web Development
Web Development Zone, Visual Basic, .NET
advertisement
Click Here