On my OS X host, I am having trouble deleting the directory "foo".

mymac:.Trashes joe$ ls
mymac:.Trashes joe$ ls foo/
Ảnh011.jpg  Ảnh012.jpg  Ảnh013.jpg
mymac:.Trashes joe$ ls -l foo/
ls: Ảnh011.jpg: No such file or directory
ls: Ảnh012.jpg: No such file or directory
ls: Ảnh013.jpg: No such file or directory
mymac:.Trashes joe$ rm -rf foo/
rm: foo/: Directory not empty
mymac:.Trashes joe$ sudo rm -rf foo/
rm: foo/: Directory not empty

As you can see, there are some files under the directory "foo" which I can only run ls on; running ls -l returns an error. I cannot delete the individual files or the directory. Using "Empty Recycle Bin" did not work either. I have also tried 'Disk Utility' -> 'Verify Disk' and 'Repair Disk'.

Edit: As requested, here are more info

mymac:.Trashes joe$ ls -del foo/
drwxrwxrwx  2 joe  staff  16384 13 May 11:19 foo/
mymac:.Trashes joe$ ls -del foo
drwxrwxrwx  2 joe  staff  16384 13 May 11:19 foo
mymac:.Trashes joe$ LC_ALL=C
mymac:.Trashes joe$ ls -ABeli foo/
total 1812
18972612676 -rwxrwxrwx  1 joe  staff  305951 13 May 11:19 Ảnh011.jpg
19123958587 -rwxrwxrwx  1 joe  staff  309745 13 May 11:19 Ảnh012.jpg
18511775654 -rwxrwxrwx  1 joe  staff  310907 13 May 11:19 Ảnh013.jpg
mymac:.Trashes joe$ find foo/
  • Does cding into the directory and doing something like rm -f -- ./* work? (I'm not sure if OSX's rm accepts the -- syntax to terminate command line processing for arguments, but don't see why it shouldn't.) – user May 15 '12 at 14:53
  • :( nope, no error, but didn't delete anything – joe May 15 '12 at 15:09
  • Maybe rm is aliased to something. Try /bin/rm instead. – hluk May 15 '12 at 16:09
  • Other thing you can try is find foo/ -type f -delete. – hluk May 15 '12 at 16:24
  • 1
    Please run the following commands show (exactly these commands, with the same options and the same punctuation): \ls -del foo, LC_ALL=C \ls -ABeli foo/, find foo/. Copy-paste the output into your question. – Gilles 'SO- stop being evil' May 15 '12 at 23:26

It appears that somehow you have entry names in foo which do not link to a valid node for a file. I'm not sure how that could happen or why rm -rf would not delete the entry from the directory even if it did.

But perhaps if you associate the directory entry with a valid file node it will delete? In other words, maybe this?

touch foo/Ảnh011.jpg
rm foo/Ảnh011.jpg

Hmmm. Does anyone else think the // in the result below is, well, unexpected?

mymac:.Trashes joe$ find foo/

I would have expected it to be as shown below. Could the // (whatever it is) have been a clue to the problem?

  • Yep I've tried that, but didnt work. touch: foo/Ảnh011.jpg: No such file or directory – joe May 16 '12 at 8:32

Have you tried renaming the files first? The files have a special character at the beginning "Ả". Try renaming the files first and then delete them.

  • Yep, tried. I got 'No such file or directory' error. – joe May 16 '12 at 8:33
  • Try using mv ?nh01?.jpg anh01?.jpg – Ruben May 17 '12 at 12:40

Replies above are good, but there's another thing you should know.

By default 'ls' (or 'ls -l') doesn't show files whose names start with a '.' (aka "dot files")

To make sure you see all files use 'ls -a'.

It is possible, although not certain that you have other files starting with a '.' in 'foo/' and that's why it is not empty.

That said, they should have been removed with '/bin/rm -rf foo' so there has to be some other issue in that dir.


Try deleting the files with this command and then delete the folder.

find . -iname '*.jpg' -exec rm {} \;
  • If rm -rf isn't working, plain rm almost certainly won't. It might be worth trying -delete, however. Which you should use instead of -exec rm anyway. – Kevin May 15 '12 at 23:03
  • Looks like I didn't understand the question. Sorry. – Ander2 May 16 '12 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.