Working in the command line is a daily reality for many developers, system administrators, and data scientists. While the terminal is powerful, typing out long commands and correcting mistakes can be slow and tedious. Fortunately, the Bash shell (the default on most Linux systems and macOS) is packed with keyboard shortcuts that can dramatically speed up your workflow.
Learning these shortcuts will help you move faster, edit more efficiently, and feel like a true command-line wizard.
Cursor Movement
Stop repeatedly tapping the arrow keys. Navigate your commands instantly.
Ctrl + A: Move the cursor to the beginning of the line.Ctrl + E: Move the cursor to the end of the line.Alt + B: Move back one word.Alt + F: Move forward one word.
Editing Commands
Quickly fix typos or change parts of your command without starting over.
Ctrl + U: Cut everything from the cursor to the beginning of the line.Ctrl + K: Cut everything from the cursor to the end of the line.Ctrl + W: Cut the word before the cursor.Ctrl + Y: Yank (paste) the last text that was cut.Ctrl + H: Delete the character before the cursor (same as Backspace).Ctrl + D: Delete the character at the cursor (same as Delete).
Command History
Don’t re-type commands you’ve already used. Access your history with ease.
Ctrl + P: Fetch the previous command (same as the Up Arrow).Ctrl + N: Fetch the next command (same as the Down Arrow).Ctrl + R: Search your command history (reverse-i-search). This is one of the most powerful shortcuts! Just start typing any part of the command you’re looking for.!!: Execute the very last command again.
Process and Screen Control
Manage running processes and your terminal view.
Ctrl + L: Clear the entire screen (same as theclearcommand).Ctrl + C: Kill the current foreground process. Use this to stop a command that is taking too long or running indefinitely.Ctrl + D: Exit the current shell (same as theexitcommand). If you press this on an empty line, your terminal session will close.Ctrl + Z: Suspend the current foreground process. The process is paused, and you can bring it back to the foreground withfgor have it continue in the background withbg.
Other Useful Shortcuts
Ctrl + M: Equivalent to the Enter key.Tab: Autocomplete commands, file paths, and variable names. Press it once for a direct completion, or twice to see all possible options.
By incorporating these shortcuts into your daily routine, you’ll find that you can work more efficiently and with less frustration in the terminal. Happy coding.