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: http://jaux.net/2009/11/24/double-hyphen-in-bash/

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 *"

Good!!

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 to godandme Cancel reply