Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash keyboard shortcuts

Bash Shortcuts

visual cheetsheet

Moving

command description
ctrl + a Goto BEGINNING of command line
ctrl + e Goto END of command line
ctrl + b move back one character
ctrl + f move forward one character
alt + f move cursor FORWARD one word
alt + b move cursor BACK one word
ctrl + xx Toggle between the start of line and current cursor position
ctrl + ] + x Where x is any character, moves the cursor forward to the next occurance of x
alt + ctrl + ] + x Where x is any character, moves the cursor backwards to the previous occurance of x

Edit / Other

command description
ctrl + d Delete the character under the cursor
ctrl + h Delete the previous character before cursor
ctrl + u Clear all / cut BEFORE cursor
ctrl + k Clear all / cut AFTER cursor
ctrl + w delete the word BEFORE the cursor
alt + d delete the word FROM the cursor
ctrl + y paste (if you used a previous command to delete)
ctrl + i command completion like Tab
ctrl + l Clear the screen (same as clear command)
ctrl + c kill whatever is running
ctrl + d Exit shell (same as exit command when cursor line is empty)
ctrl + z Place current process in background
ctrl + _ Undo
ctrl + x ctrl + u Undo the last changes. ctrl+ _ does the same
ctrl + t Swap the last two characters before the cursor
esc + t Swap last two words before the cursor
alt + t swap current word with previous
esc + .
esc + _
alt + [Backspace] delete PREVIOUS word
alt + < Move to the first line in the history
alt + > Move to the end of the input history, i.e., the line currently being entered
alt + ? display the file/folder names in the current path as help
alt + * print all the file/folder names in the current path as parameter
alt + . print the LAST ARGUMENT (ie "vim file1.txt file2.txt" will yield "file2.txt")
alt + c capitalize the first character to end of word starting at cursor (whole word if cursor is at the beginning of word)
alt + u make uppercase from cursor to end of word
alt + l make lowercase from cursor to end of word
alt + n
alt + p Non-incremental reverse search of history.
alt + r Undo all changes to the line
alt + ctl + e Expand command line.
~[TAB][TAB] List all users
$[TAB][TAB] List all system variables
@[TAB][TAB] List all entries in your /etc/hosts file
[TAB] Auto complete
cd - change to PREVIOUS working directory

History

command description
ctrl + r Search backward starting at the current line and moving 'up' through the history as necessary
crtl + s Search forward starting at the current line and moving 'down' through the history as necessary
ctrl + p Fetch the previous command from the history list, moving back in the list (same as up arrow)
ctrl + n Fetch the next command from the history list, moving forward in the list (same as down arrow)
ctrl + o Execute the command found via Ctrl+r or Ctrl+s
ctrl + g Escape from history searching mode
!! Run PREVIOUS command (ie sudo !!)
!vi Run PREVIOUS command that BEGINS with vi
!vi:p Print previously run command that BEGINS with vi
!n Execute nth command in history
!$ Last argument of last command
!^ First argument of last command
^abc^xyz Replace first occurance of abc with xyz in last command and execute it

Kill a job

n = job number, to list jobs, run jobs

kill %n

Example:

kill %1

References

  1. http://cnswww.cns.cwru.edu/php/chet/readline/readline.html
  2. https://github.com/fliptheweb/bash-shortcuts-cheat-sheet/blob/master/README.md
@romagnolid

This comment has been minimized.

Copy link

@romagnolid romagnolid commented May 7, 2018

Can I suggest to add Ctrl + h: delete character before the cursor?

@TravisRedfern

This comment has been minimized.

Copy link

@TravisRedfern TravisRedfern commented Nov 26, 2019

Can I suggest to add Ctrl + h: delete character before the cursor?

i can see its application but in reality could you not use backspace or is there situations in which backspace can't be used. Sorry I am a complete beginner on GIT

@epleterte

This comment has been minimized.

Copy link

@epleterte epleterte commented Feb 3, 2020

Ctrl + h follows the same paradigm as the others and means you don't have to move your hand if your index fingers are already resting nicely around fg/hj :--)

@Ankit-Boora

This comment has been minimized.

Copy link

@Ankit-Boora Ankit-Boora commented Nov 14, 2020

This is so much complicated to learn git or GitHub. If there is any expert please connect with me for some time.

@dontboyle

This comment has been minimized.

Copy link

@dontboyle dontboyle commented Nov 17, 2020

I'm ... WAT!? why is it ctl-y instead of ctl-v? if it's unused...

@SonkeWohler

This comment has been minimized.

Copy link

@SonkeWohler SonkeWohler commented Nov 21, 2020

I'm ... WAT!? why is it ctl-y instead of ctl-v? if it's unused...

ctrl + v in standard bash prints the verbose version of the next key that is pressed:

  • ctrl + v followed by Backspace: ^?
  • ctrl + v followed by Esc: ^[
  • and so forth

The ^ here stands for ctrl, so you could write ctrl + v as ^v. Similarly, instead of pressing Backspace you could press ctrl + ?, Enter can be ctrl + m

This is how it was setup back in the day before ctrl + c and ctrl + v started to exist, hence it is kept in most command line emulators.

@SuryanshB

This comment has been minimized.

Copy link

@SuryanshB SuryanshB commented Jan 26, 2021

git

@gp42

This comment has been minimized.

Copy link

@gp42 gp42 commented Jan 28, 2021

Ctrl + i offers similar command completion as TAB

@missits

This comment has been minimized.

Copy link

@missits missits commented Feb 21, 2021

Is there a command for opening multiple tabs in the gitbash terminal?

@albcorp

This comment has been minimized.

Copy link

@albcorp albcorp commented Apr 20, 2021

Thanks for this excellent summary. One suggestion: C-o executes the current line AND advances to the next line in the history, so that you can easily repeat a sequence of lines. This is a very powerful command

@saurin2

This comment has been minimized.

Copy link

@saurin2 saurin2 commented Apr 26, 2021

Excellent tutorial, for OS X users use Esc key for Alt key.

Is there any shortcut available to delete specific number of words before or after cursor?

@doneykoo

This comment has been minimized.

Copy link

@doneykoo doneykoo commented May 12, 2021

ctrl + d | Exit shell (same as exit command)
is conflicting with ctrl + d | Delete the character under the cursor?

@tuxfight3r

This comment has been minimized.

Copy link
Owner Author

@tuxfight3r tuxfight3r commented May 12, 2021

ctrl + d | Exit shell (same as exit command)
is conflicting with ctrl + d | Delete the character under the cursor?

Good spot, ctrl+d does both, if the cursor line is empty it closes that window.

@logbasex

This comment has been minimized.

Copy link

@logbasex logbasex commented Jun 30, 2021

$[TAB][TAB] not working with bash.


@Luciesarah

This comment has been minimized.

Copy link

@Luciesarah Luciesarah commented Jul 5, 2021

Hi, any advice on how to keep open subl . in Gitbash while being able to write other commands on a new line? Till so far I was using ctr + c, but now I need that the sublime text does not close while I'm doing other commands in Gitbash. I'm a beginner, help would be appreciated..

@albcorp

This comment has been minimized.

Copy link

@albcorp albcorp commented Jul 5, 2021

It sounds like you need to put the command in the background. When you launch it, put an ampersand at the end of the line to run the command in the background so that the command line remains available. This is not strictly a keyboard shortcut, but rather a feature of the shell

@Luciesarah

This comment has been minimized.

Copy link

@Luciesarah Luciesarah commented Jul 6, 2021

Thank you for your answer. Could you please give me advice on how to do it? Googling things does not help me at this point, since I'm learning how things work...

@albcorp

This comment has been minimized.

Copy link

@albcorp albcorp commented Jul 6, 2021

@Luciesarah Take a look at one of the primers on the unix shell like https://www.ks.uiuc.edu/Training/Tutorials/Reference/unixprimer.html

In that one, it is covered at 2

@Luciesarah

This comment has been minimized.

Copy link

@Luciesarah Luciesarah commented Jul 7, 2021

@albcorp Thanks a lot. I'm happy that it works now. Also thanks for the link, it helped me to understand the issue better. Have e great day :]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment