9

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

fmark
  • 1,837
  • 4
  • 18
  • 18
  • 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 Mar 20 '11 at 03:22

2 Answers2

23

Most GNU tools support -- to terminate the options.

rm -- -p
rm ./-p
Ignacio Vazquez-Abrams
  • 111,361
  • 10
  • 201
  • 247
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
  • 11,068
  • 1
  • 21
  • 26