Mukesh Chauhan

Just another WordPress.com weblog

Bang bang!!!


One reason people hate using command line is if something goes wrong or has to rerun the command, they have to type it all over again. Some use up arrow instead of retyping. But here is bang command typed as (!) exclamation, for your rescue.

“Bang” (!) is a very interesting command. It is very useful and can speed up your work. It saves your effort to type the commands again again.

# !!
This bang command, when entered into the bash shell will run the previous command. It does the same thing as hitting the up arrow to take you to the previous command and then hitting enter.

# !ls
This will run the last command that started with ‘ls’. If you ran ‘ls -al /etc/init.d’ a few commands ago and then you type ‘!ls’ the full command will be run again, assuming that you haven’t used that command since then.

# !ls:p
This will display the command instead of running it.

# !$
This one will run the last word of the previous command. This one is mainly useful for substitutions.

# !$:p
Instead of running the last word of the previous command this will print it out.

# !*
This bang command will run the previous command without the first word. This one is also only really useful for substitutions as we see in the examples that follow.

# !*:p
This will print the previous command without the first word.

Click here for examples.

April 16, 2010 - Posted by | Uncategorized

No comments yet.

Leave a comment