I accidentally created a folder with the name '-p' using the `mkdir` command, and now I'm stuck trying to delete it. I'm working on Ubuntu 24. The issue is that the directory's name is actually '–p', yet when I try to delete it using `rm` or `rmdir`, it gives me trouble because it thinks I'm passing options instead. Any suggestions on how to remove this folder?
4 Answers
If those methods don't work, here's another: list the inode number with `ls -i`, then use `find . -inum -exec rm {} ;`. This should help you delete it by referencing its inode directly.
Alternatively, if it's really stubborn, boot from a USB with Puppy Linux and delete the folder that way. Sometimes a live environment can handle this kind of issue better than the installed version.
You can try using `./` in front of the folder name when you delete it. Instead of `rm -p`, go for `rm ./-p`. This way, it won't get confused and treat it as an option.
Thanks for the tip!
I tried that, but it still says 'No such file or directory'. What now?
You might want to try using `rmdir -- -p`. The double dashes before the name tell the command that what follows is not an option, just a directory name. If you still can't get rid of it, there might be some hidden characters in the name. Try using tab completion after typing '-' to see if anything shows up.
I'm gonna give that a shot. Thanks!

I ended up doing just that! It worked like a charm after backing up my files.