Filenames that start with a dash

A commonly asked question concerning the use of rm is "How do I remove a filename that starts with a dash?" The problem is that rm expects anything that starts with a dash to be an option (ex. -i for interactive, or -f for force).

Here are two solutions. The first (as documented in the man page for rm) is to put a -- in after the options, but before the filename:

> rm -f -- -dashfile

The second solution is to include a full or partial pathname to specify the file:

> rm /n/foo/0/smith/-file or > rm ./-file Note that this latter approach can be applied to solve similar, syntactic problems which occur when using other commands.

Filenames with garbage characters

Sometimes files will be generated that have control characters in their names (frequently caused by line noise when you dial in). These control characters will show up as question marks in the filename when listed with "ls". Since all of the shells will interpret a question mark in a command as a substitute for any single character (see File Globbing), this should work fine, and it usually does:

> ls filename1 filename2 linenoise{x{??x The question marks are control characters > rm linenoise{x{??x > ls filename1 filename2

Sometimes this fails to work. The reason is almost certainly the fault of your shell. If your shell is cshe, it will fail to correctly select some control characters - anything with the eighth bit set will have that bit stripped out, so the shell will give the wrong filename to rm.

The simple solution is to temporarily use another shell:

> echo $SHELL /bin/cshe > tcsh > rm linenoise{x{??x Don't forget to exit the new shell: > exit >

Last Update: 1/12/94 JGW

Original author: TAF