2

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

mymac:.Trashes joe$ ls
foo
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/
Password:
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/
foo/
foo//Ảnh011.jpg
foo//Ảnh012.jpg
foo//Ảnh013.jpg
8
  • 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
    Commented May 15, 2012 at 14:53
  • :( nope, no error, but didn't delete anything
    – joe
    Commented May 15, 2012 at 15:09
  • Maybe rm is aliased to something. Try /bin/rm instead.
    – hluk
    Commented May 15, 2012 at 16:09
  • Other thing you can try is find foo/ -type f -delete.
    – hluk
    Commented May 15, 2012 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. Commented May 15, 2012 at 23:26

4 Answers 4

2

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/
foo/
foo//Ảnh011.jpg
foo//Ảnh012.jpg
foo//Ảnh013.jpg

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

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

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.

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

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.

0

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

find . -iname '*.jpg' -exec rm {} \;
2
  • 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
    Commented May 15, 2012 at 23:03
  • Looks like I didn't understand the question. Sorry.
    – Ander2
    Commented May 16, 2012 at 6:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .