SHARE
Facebook X Pinterest WhatsApp

Bash Command Line Shortcuts

I’ve been using bash for years, and I still haven’t come anywhere close to mastering the full range of available command line keyboard shortcuts. I’ve found the best way to get more under my fingers is to note a few on a Post-It stuck to the monitor, and then swap it for another one at […]

Written By
thumbnail Juliet Kemp
Juliet Kemp
Oct 15, 2008
Datamation content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

I’ve been using bash for years, and I still haven’t come anywhere close to mastering the full range of available command line keyboard shortcuts. I’ve found the best way to get more under my fingers is to note a few on a Post-It stuck to the monitor, and then swap it for another one at intervals.

Here, are a few useful candidates.

(C = control key, M = alt/meta key.)

  1. C-r and C-s : Launch an incremental search backward and forward (respectively), in your command-line history.
  2. C-j and C-g : Abandon an incremental search either with the line
    found, or with the original line (respectively).
  3. M-. or ESC then . : Both of these insert the final argument to the

    last command at the cursor point. This is useful when moving files around and
    editing them.

  4. M-C-y : Insert the first argument to the previous command at the
    cursor point. If you want the nth argument, hit M-n beforehand. So
    M-2 M-C-y would give you the 2nd argument to the previous command. (A
    lot of keys to remember, but it’s useful once in a while.)
  5. Recent Tips
    » LDAP Master Server
    » Perltidy
    » IPTraf

    Read All Tips of the Trade

  6. C-w and M-backspace : Both delete the word behind the cursor. C-w
    uses whitespace as a boundary, whereas M-backspace uses non-alphanumeric
    characters. So if you have file.txt and hit C-w, you’ll delete
    the lot, whereas M-backspace would leave you with file.. This
    has very obvious uses. (It also works with underscores.)
  7. I learned some new shortcuts while researching this, so hopefully you learned
    something useful, too!

    Ed Note: A quick note about the Perltidy tip from a fortnight ago. Thanks to
    Randal L. Schwartz for pointing out that it’s a good idea to set up tests for your code, to check that it does the same thing after Perltidy is
    finished as it did before. As he discusses here, ultimately the only thing that can interpret Perl code entirely reliably is the Perl interpreter itself. So be aware that there are circumstances in which Perltidy (and similar programs) can break code!

    This article was first published on ServerWatch.com.

      SEE ALL
    ARTICLES
     

Recommended for you...

8 Best Network Monitoring Tools of 2024 (Free & Paid)
Liz Ticong
Apr 11, 2024
OpenVAS vs. Nessus: Top Vulnerability Scanners Compared
Leon Yen
Feb 23, 2024
What is SOX Compliance? Requirements & Rules
Mary Shacklett
Oct 4, 2023
The Top Intrusion Prevention Systems
Kashyap Vyas
Jun 14, 2023
Datamation Logo

Datamation is the leading industry resource for B2B data professionals and technology buyers. Datamation's focus is on providing insight into the latest trends and innovation in AI, data security, big data, and more, along with in-depth product recommendations and comparisons. More than 1.7M users gain insight and guidance from Datamation every year.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.