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-Bor 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-For 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 .
CTRL-Hor backspace: delete the character , to the left of the cursor .
CTRL-Dor delete : Delete the character , the cursor is at . Works in emacs .
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
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 .
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-Por the up arrow : Cycle backwards in the entered commands. In emacs , this keyboard shortcut moves the cursor , to the previous line .
CTRL-Nor the down arrow : Cycle forward in the entered commands. In emacs , this will move the cursor to the next line.
CTRL-_: can be used for undo .
Inserting control characters
To insert a control character , for example
CTRL-V , or
CTRL-Z , before entering the control character sequence , precede it with keyboard sequence:
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 ..