How do I delete a folder named ‘-p’ in Ubuntu?

0
7
Asked By CuriousWanderer92 On

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

Answered By CommandLineHero On

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.

Answered By LinuxExplorer88 On

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.

CuriousWanderer92 -

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

Answered By TechSavvy260 On

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.

OpinionatedGeek42 -

Thanks for the tip!

PersistentUser70 -

I tried that, but it still says 'No such file or directory'. What now?

Answered By CodeWizard123 On

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.

TechGuru67 -

I'm gonna give that a shot. Thanks!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.