On my external hard drive are two directories, Fun.
and Complex_
, where that _ is a whitespace. I cannot empty from my trash or remove them with rm -rf
and I want to.
Neither show up in Finder on OSX, and I don't remember if they showed up in dolphin on linux. But they do show up in bash.
rm
and mv
returns No such file or directory
. Containing folders can be moved and bring the special directories with them but they cannot be deleted.
Why can ls
detect the files but rm
and mv
can't? How can I fix them? I am using \_
on the complex file. (_ is whitespace).
Edit
The characters must not be the problem. I made "test." and "test " and I had no trouble removing them using quotes. But these dirs still cannot be removed. There must be something very low level wrong with the actual files themselves
sagan:Math ptwales$ ls
Complex
sagan:Math ptwales$ ls -i
ls: Complex : No such file or directory
sagan:Math ptwales$ ls -idF *
ls: Complex : No such file or directory
sagan:Math ptwales$ find . -name * -print0
find: ./Complex : No such file or directory
sagan:Math ptwales$
Same results with Fun.
I'm guessing that the parent dir's have links to the files and know their names but files just don't exist or are corrupted somehow.
The external drive is in exFAT format. Would that be relevant?
Best Answer
rm and mv can also detect the directories just fine, but it you type:
rm file
then the shell will ignore the whitespace.There are a few things you can do to work around this. The easiest is to encapsulate the filename in quotes. Another solution is to escape the special char, e.g. with a backslash
Example:
Now to delete them, either:
rm "testfile "
, orrm testfile\
(please notice the whitespace after the backslash)As for filenames ending in a dot. I can not reproduce the problem. Are you sure it ends in a dot and not in some other special char?
If it is another char than a dot then read up on the Internal file separator in bash. You can set it to something else, or just use commands sunch as find with -print0. (Example
find /path/to/search-name 'SomeFilePattern*' -print0 | some_command
)