DEV Community

Asaduzzaman Pavel
Asaduzzaman Pavel

Posted on • Originally published at iampavel.dev

Bash Shortcuts I Use Every Day

Bash - The Bourne-Again Shell

GNU Bash is a popular command-line shell used by many Linux and macOS users. It lets you execute commands, run scripts, and interact with the system. But typing commands in bash can be tedious, especially if you repeat them often or make small changes. Bash provides keyboard shortcuts that help you save time and improve your command-line experience.

These are the shortcuts I use most often for navigation, editing, control, and history.

Navigation Shortcuts

Navigation shortcuts let you move the cursor around the current line while typing a command. They help you quickly reach the beginning or end of the line, move forward or backward by one character or one word, or switch between different positions.

command description
ctrl + a Move to the start of the command line
ctrl + e Move to the end of the command line
ctrl + b Move one character to the left
ctrl + f Move one character to the right
alt + f Move one word to the right
alt + b Move one word to the left
ctrl + xx Switch between the current and the first position of the cursor

Editing Shortcuts

Editing shortcuts let you modify the command you're typing. They help you delete, undo, cut, paste, complete, or capitalize characters, words, or lines.

Shortcut Description
ctrl + x,e Edit command in editor
ctrl + d Delete a character forward or exit the shell if the line is empty.
ctrl + h Delete a character to the left. Equivalent to backspace
alt + d Delete a word forward from the cursor.
ctrl + w Delete a word backward from the cursor. Equivalent to alt + backspace
ctrl + u Cut from cursor to start of line.
ctrl + k Cut from cursor to end of line.
ctrl + y Paste the last cut text.
alt + u Capitalize every character from cursor to end of word.
alt + l Lowercase every character from cursor to end of word.
alt + c Capitalize the character under cursor and move to end of word.
alt + t Swap current word with the previous word.
tab Complete the current word or list possible completions.

Control Shortcuts

Control shortcuts let you manage the processes running in bash. They help you stop, resume, kill, or exit processes.

Shortcut Description
ctrl + c Interrupt (kill) the current foreground process running in bash. Sends the SIGINT signal to the process, requesting termination.
ctrl + z Suspend (pause) the current foreground process running in bash. Sends the SIGTSTP signal to the process. To resume the process later, use fg process_name command.
ctrl + s Stop all output to the screen. Useful for halting verbose commands without stopping the command itself (unlike Ctrl+C).
ctrl + q Resume output to the screen after stopping it with Ctrl+S.
ctrl + l Clear the screen. Equivalent to running the clear command.
ctrl + d Close the bash shell by sending an EOF (End-of-file) marker to bash, prompting exit. Similar to running the exit command.

History Shortcuts

History shortcuts let you access and reuse previous commands you've typed in bash. They help you search, recall, edit, or run commands from your history.

Shortcut Description
ctrl + r Incremental reverse search of bash history. Type a part of a command to display the most recent matching command. Press Ctrl+R again for older matching commands. Press Enter to run or Esc to edit before running.
ctrl + s Incremental forward search of bash history. Similar to Ctrl+R but searches forward.
alt + p Non-incremental reverse search of bash history. Type a part of a command and press Alt+P to see older matching commands. Press Enter to run or Esc to edit before running.
alt + n Non-incremental forward search of bash history. Similar to Alt+P but searches forward.
ctrl + p or up arrow Move to the previous command in history.
ctrl + n or down arrow Move to the next command in history.
ctrl + o Run the current command and re-enter it in history.
ctrl + g Exit the history search mode without running the command.
!! Run the last command in history.
!* Run the last command in history except its first word.
!:p Display what ! substitutes.
!x Run the most recent command in history that begins with x.
!x:p Display the x command and add it as the most recent command in history.
!$ Substitute the last argument of the previous command in the current command.
!^ Substitute the first argument of the previous command in the current command.
^123^abc Replace 123 with abc in the previous command and run it.

Bash keyboard shortcuts are powerful tools that can improve your productivity when working with the command-line shell. I use these shortcuts daily and they've become second nature. Here's hoping they help you work faster too.

Resource Link
GNU Bash https://www.gnu.org/software/bash/{rel="external" target="_blank"}
GNU Bash Manual https://www.gnu.org/software/bash/manual/bash.html{rel="external" target="_blank"}

Top comments (0)