Tuesday, December 11, 2007

Removing a file whose name begings with "-" e.g. -C

This is funny. I was doing some tar's of directories. The tar happened, but due to my mistake the tar name became -C . I was trying to move/delete the same, tried single quote/double quote/escape.. Nothing worked.Came to know about the solution from one of my colleague.

Since the file name begins with -, commands like mv, rm treats the file name itself as a parameter(option) to the command. To nullify this affect, we have to put -- before the file name.

rm -- -C

one more way:

rm ./-C

No comments:

© Jadu Saikia www.UNIXCL.com