# Keyboard Shortcuts at the Prompt

Ctrl+A and Ctrl+E jump to the start and end of the command line, Alt+B and Alt+F move a word at a time, Ctrl+W and Ctrl+U delete a word or the line, and Alt+. brings back the last command's last argument.

Apprentice · Unix · Linux · Updated November 10, 2026

## After this lesson you can

- Move along the command line with Ctrl+A, Ctrl+E, Alt+B and Alt+F, and clear the screen with Ctrl+L
- Delete a word or the whole line with Ctrl+W and Ctrl+U, and bring back the last argument with Alt+.

## Key takeaways

- Ctrl+A jumps to the start of the line and Ctrl+E to the end, so a fix at the far end of a long command takes one key.
- Alt+B and Alt+F move back and forward a word at a time. In a path, each folder name is a word.
- Ctrl+W deletes back to the last space, so a whole path goes at once. Ctrl+U deletes everything before the cursor, and Ctrl+Y puts it back.
- Alt+. types the last argument of the command before, such as a long path you used a moment ago. Press it again for older ones.
- On a Mac, Alt is the Option key, and the Terminal app needs "Use Option as Meta key" turned on first.

You've typed a long command, sixty letters of folder names, and before you press Enter you spot what's wrong: it needs one more option right after the command, at the far end of the line. Hold the left arrow, and the cursor crawls back a letter at a time. People who work in a terminal all day, such as a web developer fixing a server or an IT tech helping someone over the phone, don't crawl. They use a handful of key combinations that jump to the start, the end, or one word along, and delete a whole word at once. They're the terminal's version of Home and End in a document, and once your fingers know them, long commands stop being a chore.

## Set up the practice folder

This chapter's lessons use a photo-editing project with folders several levels deep: raw photos sorted by month and place, the edited copies, and folders for the finished exports. The photos are empty files with photo names, which is all the terminal needs to practice on. The lines are safe to run again.

```bash
mkdir -p ~/terminal-practice/photo-project && cd ~/terminal-practice/photo-project
mkdir -p raw/2026/{04-april/park,05-may/beach,06-june/lake} \
  edited/2026/{04-april/park,05-may/beach} exports/{web,print}
touch raw/2026/04-april/park/IMG_04{12,13,14}.jpg raw/2026/05-may/beach/IMG_05{01,02,03}.jpg \
  raw/2026/06-june/lake/IMG_06{20,21}.jpg
touch edited/2026/04-april/park/IMG_0412-edit.jpg edited/2026/05-may/beach/IMG_05{01,03}-edit.jpg
printf '%s\n' 'Spring photo show: three photos for the web page' \
  'Beach: IMG_0501 and IMG_0503 are edited' > notes.txt
```

The keys below are the same on Linux, in WSL on Windows, and in zsh on a Mac, with the differences noted. On a Mac, Ctrl is the Control key, not Command.

## Jump to the start or the end: Ctrl+A and Ctrl+E

Type this line, and don't press Enter yet:

```text
$ cp raw/2026/05-may/beach/IMG_0502.jpg edited/2026/05-may/beach/
```

You'd like `cp -i`, which asks before it replaces a file (*Copy, Move and Rename: cp and mv*). Press **Ctrl+A** (hold Ctrl and press A): the cursor jumps to the start of the line, A for the start of the alphabet. Press the right arrow twice, past `cp`, and type a space and `-i`:

```text
$ cp -i raw/2026/05-may/beach/IMG_0502.jpg edited/2026/05-may/beach/
```

Now the copy needs a name of its own. Press **Ctrl+E**, E for the end, and type `IMG_0502-edit.jpg`:

```text
$ cp -i raw/2026/05-may/beach/IMG_0502.jpg edited/2026/05-may/beach/IMG_0502-edit.jpg
```

Press Enter, and the copy is made. Wherever the cursor is, Enter runs the whole line.

## A word at a time: Alt+B and Alt+F

Ctrl+A and Ctrl+E jump to the ends. To land in the middle, move a word at a time: **Alt+B** goes back a word and **Alt+F** goes forward one. For these keys a word is letters and numbers, so in a path each folder name is a word of its own. Type `ls raw/2026/beach`, which is missing the month. Press Alt+B once: the cursor jumps back to the start of `beach`. Type `05-may/`:

```text
$ ls raw/2026/05-may/beach
```

Press Enter:

```text
IMG_0501.jpg  IMG_0502.jpg  IMG_0503.jpg
```

On a Mac, Alt is the **Option** key, and it works for this only after you turn on **Use Option as Meta key** in the Terminal app's Settings, under Profiles, then Keyboard. Without it, press Esc and then the letter: Esc then B does the same as Alt+B, in any terminal. zsh counts a whole path as one word, so there Alt+B jumps back to the start of `raw/2026/beach`.

## Delete a word or the whole line: Ctrl+W and Ctrl+U

Type `cp notes.txt exports/web/`, then change your mind: it should go to `print`. **Ctrl+W** deletes the word before the cursor, and for Ctrl+W a word runs back to the last space, so the whole path goes at once:

```text
$ cp notes.txt
```

Type `exports/print/`, and the line is fixed. **Ctrl+U** deletes everything before the cursor. With the cursor at the end, that's the whole line, and you have an empty prompt again.

What Ctrl+U deletes isn't lost: **Ctrl+Y** puts it back. That makes it handy halfway through a long command, when you need to check something first. Type `cp raw/2026/06-june/lake/IMG_0620.jpg edited/2026/06-june/lake/` and wonder whether that folder exists yet. Press Ctrl+U, run `ls edited/2026`, see that it doesn't, and make it with `mkdir -p edited/2026/06-june/lake`. Then press Ctrl+Y, and your line is back, ready for Enter:

```text
$ ls edited/2026
04-april  05-may
$ mkdir -p edited/2026/06-june/lake
$ cp raw/2026/06-june/lake/IMG_0620.jpg edited/2026/06-june/lake/
```

In zsh, Ctrl+U deletes the whole line wherever the cursor is.

## The last argument again: Alt+. and a clean screen

The last word of a command is often the long path you're about to need again: you make a folder, then go into it. **Alt+.** (Alt and the period key) types the last argument of the command before, the word at its end. Run `ls exports`, then `mkdir -p exports/web/large`. Now type `cd `, with a space, and press Alt+.:

```text
$ ls exports
print  web
$ mkdir -p exports/web/large
$ cd exports/web/large
```

Press Alt+. again, before Enter, and it swaps in the last argument of the command before that, `exports`; each press steps one command further back. Alt+. works the same in zsh. When the screen gets full, **Ctrl+L** clears it, as `clear` does (*Your Command History*), even halfway through typing a line.

## Check yourself

2 questions to try on the lesson page.

## So what

Ctrl+A, Ctrl+E, Alt+B, Alt+F, Ctrl+W, Ctrl+U and Alt+. turn fixing a long command from a crawl into a few keystrokes. Pick two to use this week, and add one more each week.

## Key terms

- [Keyboard Shortcut](https://www.ask-codey.com/glossary/keyboard-shortcut)
- [Command Line](https://www.ask-codey.com/glossary/command-line)
- [Argument](https://www.ask-codey.com/glossary/argument-unix)

## Cheat sheets

- [Keyboard Shortcuts at the Prompt](https://www.ask-codey.com/cheat-sheets/bash-keyboard-shortcuts-cheat-sheet)

## Related

- [Your Command History](https://www.ask-codey.com/lessons/bash-command-history)
- [History Tricks: !!, !$ and Ctrl+R](https://www.ask-codey.com/lessons/bash-history-tricks)

Source: https://www.ask-codey.com/lessons/bash-keyboard-shortcuts
