Double hyphen —

Ah!! Finally I understood the significance (and application) of "–" in linux commands. The "–" is a special switch in the linux commands (only those commands who parses the command line arguments by getopts()) which indicates that any text after "–" will not be considered as option. For example, "ls -r — -l" command will not be evaluated as "ls -lr" but as [ls -r "-l"] where "-l" will be treated as a file name.

Here is the excerpt from a link:

Thus -- allows you to view a file with a name that starts with a hyphen… -- argument works with all Linux utilities that use the getopts builtin… This argument is particularly useful when used in conjunction with rm to remove a file whose name starts with a hyphen (rm -- -fname)…

Now consider the following sequence of commands:

> touch — -rf\ *
This will create a file name called "-rf *"

How to remove this file? A simple "rm -rf *" will remove all the contents instead of the file "-rf *" :P To delete this kind of file, you will have to use "–".

> rm — "-rf *"



7 thoughts on “Double hyphen —

  1. Yeh….and another thing is…quota system is in india for 50 year…if ****** goverment can not improve the backword class in 50 years …. it is not the right way….im also posting on my lj about this,…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s