Keyboard shortcuts in bash and zsh
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!
Print/View all Posts Comments on this article
SponsoredWhite Papers, Webcasts, and Downloads
- Choosing the Best CRM for Your Organization Oracle
- TechRepublic Resource Guide - VoIP Best Practices TechRepublic
- TechRepublic Resource Guide - IP-PBX Technical Strategies TechRepublic
- Live Webcast: The Top 5 Ways to Save Money with CRM TechRepublic
- Sales 2.0: How Businesses are Using Online Collaboration to Spark Sales Oracle
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
