Command line editing keyboard shortcuts

The command line , is the place where you type in your commands , to be interpreted and executed by the shell .

The command line is located just after the shell prompt , which usually has the format: username@host:currentWorkingDirectory$. The cursor is indicated on the command line , following the shell prompt , using a rectangle .

These are the shortcuts , for editing the command line . These shortcuts work on linux , freeBSD , and macOS .

Some of these keyboard shortcuts , also work in emacs . It is noted when they do .

Moving the cursor

All cursor moving , keyboard shortcuts , work also in emacs .

  • CTRL-B or left arrow : Move the cursor backward , one character to the left .
  • ALT-B : Move the cursor backward one word .
  • CTRL-A : Move the cursor backward , to the start of the line .
  • CTRL-F or right arrow: Move the cursor forward , one character to the right .
  • ALT-F : Move the cursor forward one word .
  • CTRL-E : Move the cursor forward , to the end of the command line .

Deleting

  • CTRL-H or backspace: delete the character , to the left of the cursor .
  • CTRL-D or delete : Delete the character , the cursor is at . Works in emacs .

Cutting

  • CTRL-W : Cut one word , to the left of the cursor .
  • CTRL-U : Cut everything , to the left of the cursor .
  • ALT-D : Cut one word starting where cursor is at . Works in emacs
  • CTRL-K : Cut everything from the character the cursor is at , till the end of line . Works in emacs .

The cut text can only be pasted in the terminal. To paste it , you must use CTRL-Y .

If you want to copy the text in the terminal , to paste in another program , you can select all the text using your mouse , and then you can use the keyboard shortcut: CTRL-SHIFT-C , to copy the selected text .

After that , you can paste it to another program , using your operating system paste keyboard shortcut , for example COMMAND+V on macOS .

Pasting

  • CTRL-Y : Paste the cut text from the command line , on the command line. This keyboard shortcut works also in emacs.
  • CTRL-SHIFT-V : Paste copied text from anywhere , to the command line.

Cycling through the entered commands

  • CTRL-P or the up arrow : Cycle backwards in the entered commands. In emacs , this keyboard shortcut moves the cursor , to the previous line .
  • CTRL-N or the down arrow : Cycle forward in the entered commands. In emacs , this will move the cursor to the next line.

Undoing

  • CTRL-_ : can be used for undo .

Inserting control characters

To insert a control character , for example CTRL-C , CTRL-V , or CTRL-Z , before entering the control character sequence , precede it with keyboard sequence: CTRL-V .

Spanning the command line multiple lines

This is not a keyboard shortcut , but it is related to command line editing .

To span the command line multiple lines , the backslash character: \ , can be used . Entering the backslash character: \ , and pressing enter , will move the cursor to the next line , instead of terminating the command line editing .

$ ls -\
> al
total 8
drwxr-xr-x  2 difyel difyel 4096 Sep 22 05:46 .
drwxr-xr-x 17 difyel difyel 4096 Nov  8 15:47 ..