search by tags

for the user

adventures into the land of the command line

deleting files & directories named stupidly

so you’ve tried to create a new directory and your ‘chubby fingers/dyslexia/short attention span/office distractions/insert excuse here’ has caused you to accidentally create a directory that looks like this

-rwxrwxrwx 1 root root   9942 2015-08-24 17:35 file
drwxrwxrwx 1 root root  21082 2015-08-25 10:29 dir
drwxrwxrwx 1 root root  21082 2015-08-25 10:29 -p

you try to delete it with

$ sudo rm -rf -p

hmmm… rm doesn’t have a -p option… woah wait whaaaat?

if you accidentally create a file or directory that looks like a switch such as ’-p’ or ’-rf’, you can remove it by first finding the inode number of the file or directory using

$ ls -il

675937 -rwxrwxrwx 1 root root   9942 2015-08-24 17:35 file
675938 drwxrwxrwx 1 root root  21082 2015-08-25 10:29 dir
297486 drwxrwxrwx 1 root root  21082 2015-08-25 10:29 -p

so the inode is listed in the leftest column

to remove it if it is a file

$ find . -inum 297486 -exec rm {} \;

to remove it if it is a directory

$ find . -inum 297486 -exec rmdir {} \;

nod.