1

While creating a new folder I didn't realise that in BASH ' is a special character, which means I ended up with a folder named

One Flew Over the Cuckoos\ Nest\ \(1975\)?quit?quit()?ls??????????

or to be precise

drwxrwxrwx    1 root     root             0 Mar  8 23:21 One Flew Over the Cuckoos\ Nest\ \(1975\)?quit?quit()?ls??????????

which is making my terminal freak out: Tab completion doesn't find it at all. If I try to open it via its inode I get an error:

LibreELEC:/var/media/MYNAME/Films # rm -r "$(find -inum 187)"
rm: can't remove './One Flew Over the Cuckoos\ Nest\ \(1975\)
quit
quit()
ls': No such file or directory

How badly did I mess up?

  • Almost certainly the reason it didn't work is that your filename ended with several newlines (displayed by ls as questionmarks), and "$( command )" removes trailing newlines (but passes anything else unchanged). Notice that the error message showed the problematic filename value in singlequotes as ./One ... quit newline quit() newline ls _no newlines_ – dave_thompson_085 Mar 09 '20 at 03:45

2 Answers2

3

Solved. I did it by deleting it via its inode, as I'd tried in the OP, but now using the following line which bypasses the filename altogether:

find . -inum 187 -delete

to anyone reading this, 187 should be replaced by the inode found via ls -li

2

You can use the interactive option in rm. It will list each file and ask if you want to delete it. So you can wildcard just the bits that are plain test:

rm -i *Flew*Cuckoo*Nest*

That doesn't work for rmdir. If the directory is empty, you can:

rm -ir *Flew*Cuckoo*Nest*

Or you can just rename the directory to something you can type, provided you can match enough of it for uniqueness:

mv *Flew*Cuckoo*Nest* BetterCuckooName
Paul_Pedant
  • 8,679