How do I delete a file named "-p" from bash?

9

2

How do I delete a file named -p in bash? Trying rm "-p" complains that -p is not a valid argument.

fmark

Posted 2010-06-04T03:50:55.603

Reputation: 1 587

You write "delete a file" yet the title says "delete a folder". Please make the question consistent so that it gets properly indexed. – sam hocevar – 2011-03-20T03:22:44.957

Answers

23

Most GNU tools support -- to terminate the options.

rm -- -p
rm ./-p

Ignacio Vazquez-Abrams

Posted 2010-06-04T03:50:55.603

Reputation: 100 516

1Not just GNU tools, but all POSIX-compliant tools, and in practice all non-antique unix tools. – Gilles 'SO- stop being evil' – 2011-09-08T21:58:40.113

2

The NOTE section in the man page for rm has something to say exactly about this. Apart from what Ignacio Vazquez-Abrams has mentioned in their answer, one other way of removing such files, as mentioned in the man page, is by using an absolute path reference, such as: rm /home/user/-p.

ayaz

Posted 2010-06-04T03:50:55.603

Reputation: 8 106