next up previous contents
Next: Basic Directory Commands Up: Basic File Commands Previous: Delete   Contents

Dealing with odd file names

It is possible, usually by mistake, to create files with names containing characters such as '*' and '-'. Care has to be taken when using commands with such files. For example this is not the way to remove the file called '*':-

rm *

True it will indeed remove that file - and any other in the directory. If the name involves '*', then put single quotes round the file name. This is the right way to remove that pesky file:-

rm '*'

The character '-' presents a second problem if it appears at the start of the file name: by default a reference to the file is assumed to be an option. For example a silly file called '-l' cannot be deleted with:-

rm -l

Unix complains about an invalid option. Adding single quotes:-

rm '-l'

doesn't help, instead you have to use the special option '--' which means that anything on the command line beyond it isn't an option, so what's needed is:-

rm -- -l


next up previous contents
Next: Basic Directory Commands Up: Basic File Commands Previous: Delete   Contents
P.D. Gronbech (IT Staff) 2015-10-02