# Becoming faster with the command line

**URL:** <https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990>\
**Category:** General Discussion\
**Tags:** command-line\
**Created:** [August 28, 2018, 3:08am UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990 "2018-08-28T03:08:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [August 28, 2018, 3:08am UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990/1 "2018-08-28T03:08:15Z")

</div>

A few people have asked about the command line recently. Here are some common keyboard shortcuts that make using the command line much faster:

- ctrl + a – move to beginning of line
- ctrl + e – move to end of line
- ctrl + k – delete to end of line
- ctrl + u – delete to beginning of line
- alt + b – move back one word
- alt + f – move forward one word
- alt + d – delete one word forward
- ctrl + p and ctrl + n – move up and down through command history (also ↑ and ↓)
- ctrl + r – search through previously-typed commands
- ctrl + x + u – undo
- ctrl + x + e – open the current line in a text editor (uses `$EDITOR` – probably vim by default)

Those work in Linux and probably on Windows if you’re using bash. I’m not sure how alt is handled on Mac.

If anyone has other tips for using the command line more quickly, post them below.

---

<div class="post-metadata">

**Author:** ![emd](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/emd/32/183_2.png) [@emd](https://forum.codeselfstudy.com/u/emd)\
**Post date:** [October 25, 2018, 6:12am UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990/2 "2018-10-25T06:12:01Z")

</div>

The fact is, most of these (except for the last four) are just emacs commands. When you say “command line”, I assume you mean the bash interactive shell. In fact, these are applicable more widely than the bash context. They are common in most keyboard text interaction contexts. Next time you are interacting with a text input box, whether it be a text input on a Web form or a text input box for a local application or utility on your computer, try some of the emacs control sequences, especially the first three above, but also

- \<ctrl\>-y (“yank” buffer) after a \<ctrl\>-k
- \<ctrl\>-b (back one character)
- \<ctrl\>-f (forward one character)
- \<ctrl\>-t (transpose characters)

By the way, \<alt\> is just \<cmd\> on the Mac in this context, and in many others.

---

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [October 25, 2018, 7:37pm UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990/3 "2018-10-25T19:37:31Z")

</div>

> [@emd](#):
>
> When you say “command line”, I assume you mean the bash interactive shell.

I guess bash is default on most computers. I’m using zsh at the moment.

---

<div class="post-metadata">

**Author:** ![beta23](https://forum.codeselfstudy.com/letter_avatar_proxy/v4/letter/b/5f8ce5/32.png) [@beta23](https://forum.codeselfstudy.com/u/beta23)\
**Post date:** [March 13, 2019, 11:11pm UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990/4 "2019-03-13T23:11:10Z")

</div>

Terminal User Guide: Keyboard shortcuts for Terminal on Mac

[Terminal Shortcuts](https://support.apple.com/guide/terminal/keyboard-shortcuts-trmlshtcts/mac)

---

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [March 13, 2019, 11:34pm UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990/5 "2019-03-13T23:34:18Z")

</div>

Thanks – that question just came up here at the cafe a bit earlier. 🙂

---

<div class="post-metadata">

**Author:** ![OutsourcedGuru](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/outsourcedguru/32/983_2.png) [@OutsourcedGuru](https://forum.codeselfstudy.com/u/OutsourcedGuru)\
**Post date:** [September 11, 2019, 6:44pm UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990/6 "2019-09-11T18:44:58Z")

</div>

I will use the command line history as a way of saving time. The command by itself is `history` which shows a report with PIDs. You can then re-run the one you want with the `!1234` syntax.

But since I’m always doing the following construct `history | grep foo` I created a profile alias called `fistory` (“find” + “history”) which is the first three parts of that. So `fistory service` would then display any commands which include that term.

---

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [November 21, 2019, 4:47pm UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990/7 "2019-11-21T16:47:35Z")

</div>

Here’s a cheatsheet that I found this morning. Click “Emacs Mode” for the default keybindings. “Vim mode” starts at the top of the page.

[https://gnureadline-reference.herokuapp.com/reference/](https://gnureadline-reference.herokuapp.com/reference/)

---

<div class="post-metadata">

**Author:** ![vietkieutie](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/vietkieutie/32/178_2.png) [@vietkieutie](https://forum.codeselfstudy.com/u/vietkieutie)\
**Post date:** [December 25, 2019, 7:28pm UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990/8 "2019-12-25T19:28:00Z")

</div>

Just added this as a screenshot to my desktop. 🙂

---

<div class="post-metadata">

**Author:** ![rkazak](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/rkazak/32/2796_2.png) [@rkazak](https://forum.codeselfstudy.com/u/rkazak)\
**Post date:** [April 2, 2020, 5:44am UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990/9 "2020-04-02T05:44:32Z")

</div>

If you use emacs then you can use the key-bindings in the shell for searching, so ctrl-r for reverse search of your history…

---

<div class="post-metadata">

**Author:** ![rkazak](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/rkazak/32/2796_2.png) [@rkazak](https://forum.codeselfstudy.com/u/rkazak)\
**Post date:** [April 2, 2020, 5:46am UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990/10 "2020-04-02T05:46:53Z")

</div>

Alt is the escape-key on a Mac

---

<div class="post-metadata">

**Author:** ![al-fontes-jr](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/al-fontes-jr/32/1371_2.png) [@al-fontes-jr](https://forum.codeselfstudy.com/u/al-fontes-jr)\
**Post date:** [April 2, 2020, 2:26pm UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990/11 "2020-04-02T14:26:08Z")

</div>

ctrl+D = exit out of the shell and close the terminal window (technically, it’s an EOF).

---

<div class="post-metadata">

**Author:** ![OutsourcedGuru](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/outsourcedguru/32/983_2.png) [@OutsourcedGuru](https://forum.codeselfstudy.com/u/OutsourcedGuru)\
**Post date:** [April 2, 2020, 7:10pm UTC](https://forum.codeselfstudy.com/t/becoming-faster-with-the-command-line/990/12 "2020-04-02T19:10:15Z")

</div>

I needed a ubiquitous keyboard macro in macOS for anything with a Terminal session.

_Terminal -\> Preferences -\> Profiles tab -\> Basic (default) -\> Keyboard tab -\> [+] -\> Setup Key/Modifier/Action_

In this case, I now have Ctl+F12 type something with a hard return (`\012`) at the end.
