bluethundr
bluethundr

Reputation: 1345

Delete files with special characters in filenames in linux

I've accidentally created files with names that won't allow me to delete them:

-d
--header

Doing the following has no effect:

rm -f '-d'
rm -f '--header'
unlink ('-d');
unlink ('--archive');

Unlink gives an error:

unlink: invalid option -- 'd'
Try 'unlink --help' for more information.

How can I get rid of these files?

Upvotes: 1

Views: 93

Answers (1)

0stone0
0stone0

Reputation: 44264

Use -- to tell BASH that the command options has ended, then, all other parameters are treated as positional parameters so they wont be interpreted by rm;

rm -- --header
rm -- --d

Screenshot of example

More on --: What does “--” (double-dash) mean?

Upvotes: 2

Related Questions