Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
    
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.) –  Michael Kjörling 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 May 15 '12 at 23:26
show 3 more comments

5 Answers 5

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
share|improve this answer
    
Yep I've tried that, but didnt work. touch: foo/Ảnh011.jpg: No such file or directory –  joe May 16 '12 at 8:32
add comment
up vote 0 down vote accepted

Thank you all for trying to help. It's just so annoying to see so I formatted the drive and these weird files are now gone!! At last!

share|improve this answer
    
You've still got me wondering (1) what the heck got written to that directory and (2) how it happened. Oh, well. –  irrational John May 16 '12 at 13:00
1  
Pity we didn't think to try running fsck just to see what it would come back with. –  irrational John May 16 '12 at 13:06
    
These files were valid images and I just did delete, clear recycle bin and a message just pop up saying cannot delete or something like that. Since then they were stuck and became some sort of "invalid/broken" file. I did try "Repair Disk" although not exactly fsck. –  joe May 20 '12 at 2:33
add comment

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

find . -iname '*.jpg' -exec rm {} \;
share|improve this answer
    
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
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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