How to delete files with dash or any special character?
Have you tried to delete a who-knows-where-it-came-from file which has a special character like preceded with dash or question mark? I bet that when you tried to delete it, you got something like this:
[root@rai01 home]# rm -ucantdeleteme
rm: invalid option — u
Try `rm ./-ucantdeleteme’ to remove the file `-ucantdeleteme’.
Try `rm –help’ for more information.
Now what?
The reason behind this is because the rm command is treating the dash (-) as an additional parameter or option. So since -ucantdeleteme is not a valid option for rm to use, but a file, the rm command returns an error.
One trick that I always use to get around this is to tell the rm that you are referring to something that is a file. You can do this by adding ./ before the filename, like so:
[root@rai01 home]# rm ./-ucantdeleteme
rm: remove regular empty file `./-ucantdeleteme’? y
Voila! You can now delete that pesky file. You can also do this to files with ? in their filenames.
Popularity: 9% [?]




















Leave a comment