iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
⌨️

Essential Shell Shortcut Keys for Mac

に公開

Introduction

This article summarizes frequently used shell shortcut keys. By using shortcut keys, you can streamline your command-line operations and improve productivity. In this article, I will introduce basic shortcut keys for shell operations on Mac.

Cursor Movement

Cursor operations within the shell are crucial for quickly editing long command lines.

Key Description Example Use Case
Ctrl + a Move to the beginning of the line Useful for quickly moving to the starting position to correct a command.
Ctrl + e Move to the end of the line Helpful when you want to add options after typing a command.
Ctrl + f Move forward 1 character Used to move the cursor.
Ctrl + b Move backward 1 character Used to move the cursor.
Option (Meta key) + f or Esc + f Move forward 1 word Useful for editing long paths or commands.
Option (Meta key) + b or Esc + b Move backward 1 word Useful for editing long paths or commands.

Text Editing

Being able to quickly delete or transpose text in the shell makes it easier to correct command mistakes.

Key Description Example Use Case
Ctrl + d Delete character at cursor Convenient for quickly fixing typos.
Ctrl + h Delete character before cursor Useful for going back to fix typos.
Ctrl + k Delete from cursor to end of line Great for clearing out unnecessary parts all at once.
Ctrl + u Delete from cursor to beginning of line Useful for resetting the entire command.
Ctrl + w Delete word before cursor Convenient for deleting incorrect arguments or options.
Ctrl + y Paste the last deleted string (yank) Useful for restoring content deleted just before.
Ctrl + t Transpose character at cursor with previous Corrects cases where characters were swapped due to typos instantly.
Option (Meta key) + d or Esc + d Delete word after cursor Convenient for deleting incorrect arguments or options.
Option (Meta key) + u or Esc + u Uppercase from cursor to end of word Use when you want to convert to uppercase.
Option (Meta key) + l or Esc + l Lowercase from cursor to end of word Use when you want to convert to lowercase.

History

By using history effectively, you can reuse past commands and improve your workflow.

Key Description Example Use Case
Ctrl + r Search history Useful for quickly calling up previously used commands.
Ctrl + p or ↑ Show previous command Convenient for re-executing the immediate previous command.
Ctrl + n or ↓ Show next command Useful when you want to move to the next command.

History Search (Ctrl + r)

Key bindings available during history search mode are shown below. These are particularly useful when you want to quickly find a specific command from a long history.

Key Description
Text input Search history
Ctrl + r Show previous search result
Ctrl + g Exit history search
Enter Execute the selected command
Esc Return to the shell while keeping the search result displayed

Other

Finally, I will introduce other shortcuts frequently used in shell operations. Remembering these will further improve your work efficiency.

Key Description Example Use Case
Tab Completion Convenient for auto-completing commands or paths.
Ctrl + l Clear screen Useful when you want to reset and organize the screen.
Ctrl + c Terminate the running process Allows you to immediately stop a process executed by mistake.
Ctrl + z Suspend the running process Convenient when you want to pause a process and resume it later.

Summary

Learning shortcut keys directly leads to more efficient shell work. Start by actually using the keys introduced in this article and gradually incorporate them into your workflow. Use the shortcut keys you've mastered to make shell operations on Mac even more comfortable.

Discussion