10 Amazing and Mysterious Uses of (!) Symbol or Operator in Linux Commands

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

13 Responses

  1. Amit Kumar Tripathi says:

    Simply Awesome

  2. Edgar Allen says:

    You might also mention !?

    It finds the last command with its’ string argument. For example, if…
    1013 grep tornado /usr/share/dict/words
    1014 grep hurricane /usr/share/dict/words
    1015 wc -l /usr/share/dict/words

    are all in the history then !?torn will grep for tornado again where !torn would search in vain for a command starting with torn.

    And `wc !?torn?:2` works to select argument two from the command containing tornado and run `wc` on it.

  3. Stephen says:

    I didn’t see a mention of historical context in the article, so I’ll give some here in the comments. This form of history command substitution originated with the C Shell (csh), created by Bill Joy for the BSD flavor of UNIX back in the late 70’s. It was later carried into tcsh, and bash (Bourne-Again SHell).

    Personally, I’ve always preferred the C-shell history substitution mechanism, and never really took to the fc command (that I first encountered in the Korne shell).

    • Avishek Kumar says:

      Dear Stephen,
      Thanks for the wonderful piece of Information. Keep connected and keep us aware of such context.

  4. suzy says:

    4th command. You can access it much simpler. There are actually regular expressions:
    ^ is at the begging expression
    $ is at the end expression
    :number any number parameter

    touch a.txt b.txt c.txt
    echo !^ –> display first parameter
    echo !:1 –> also display first parameter
    echo !:2 –> display second parameter
    echo !:3 –> display third parameter
    echo !$ –> display last (in our case 3th) parameter
    echo !* –> display all parameters

    • Avishek Kumar says:

      And we did the same

      echo “1st Argument is : !^”
      $ echo “2nd Argument is : !cp:2”

      echo followed by 1st argument and 2nd argument is just to make the tutorial and command understandable. I have used ‘!^’. ‘!command:number’ as you are suggesting.

      I would like to know if you mean something different?

  5. Tomasz Wiszkowski says:

    I think (5) works differently than you pointed out, and redirection to devnull hides it, but ZSh still prints the command.
    When you invoke “! ls…”, it always picks the last ls command you executed, just appends your switches at the end (after /dev/null).

    One extra cool thing is the !# operator, which picks arguments from current line. Particularly good if you need to retype long path names you already typed in current line. Just say, for example

    cp /some/long/path/to/file.abc !#:1

    And press tab. It’s going to replace last argument with entire path and file name.

    • Avishek Kumar says:


      For your first part of feedback: It doesn’t pick the last command executed and just to prove this we have used 4 different switches for same command. ($ ! ls $ ! ls -l $ ! ls -la $ ! ls -lA ). Now you may check it by entering the keywords in any order and in each case it will output the same result.

      As far as it is not working in ZSH as expected, i have already mentioned that it i have tested it on BASH and most of these won’t work in other shell.

      For the second part, what you mentioned is a HASH TAG in Linux Command Line and we have included it in one of our article. You may like to read it here: https://www.tecmint.com/linux-commandline-chat-server-and-remove-unwanted-packages/

  6. Manu says:

    Nice Article

  7. Tachyon says:

    Great post. Thanks, I’ve reshared it to G+

    One note, “su” stands for “switch user” not “Suitable User”. Minor note.
    At least that’s still representative of what it actually does, unlike when most people refer to it as “Super User”, thinking it only grants root user status, which is utterly incorrect.

Leave a Reply to Stephen Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.