I was clearing a music folder in my external drive and found a directory I can't delete no matter what I try.
If I put it in trash bin via GUI
The operation can’t be completed because the item “folder” is in use.
If I use rm -rf
to remove it via terminal
$ rm -rf folder/
rm: folder/: Directory not empty
If I use ls -la
to check its content
$ ls -la
total 512
drwxrwxrwx 1 user staff 131072 Jan 3 2017 .
drwxrwxrwx 1 user staff 131072 Jan 3 2017 ..
If I use rm -i *
within the folder
$ rm -i *
rm: 03 - Ēlusion.mp3: No such file or directory
If I use sudo lsof +D folder/
to check if any files are opened
Nothing returns on program exit.
If I use Disk Utility to repair (first aid) disk and volume
Health check passed so no repair was initiated.
If I reboot macOS
The issue persists.
Additional info:
-
I can move the folder within the drive, but not to another drive.
-
I can rename the folder.
-
ls -i *.mp3
returnsls: 03 - Ēlusion.mp3: No such file or directory
, same asrm -i *.mp3
. -
The file doesn't show up in Finder, that's confusing part, whatever filename display issue Terminal could have (I always set it to use
Unicode - UTF-8
), I think there are more force at play.
In response to questions, nope, ls -ib
doesn't return anything.
$ ls -i
$ ls -ib
$ ls -laib
total 512
2762318 drwxrwxrwx 1 user staff 131072 Jan 3 2017 .
2685260 drwxrwxrwx 1 user staff 131072 Jan 3 2017 ..
So apparently there is something in it but ls -la
couldn't see it, while rm -i
is being weird with filename?
get info
via GUI context menu did confirm there is 1 item in the folder, but with zero byte, and certainly doesn't show up in finder.
I am not sure what to do at this point. Help much appreciated!
(Using 10.13.4 + ExFAT on external drive)
Best Answer
The problem appears to be caused by a file named 03 - Ēlusion.mp3 located within the directory named folder.
Because Terminal.app is unable to render diacritical marks in file names--well, it is, but that's beyond the scope of providing the simplest solution for you--it hides its failure by hiding the filename (something unheard of by me before now; perhaps its High Sierra's changes to /.file, /.volfs and 64-bit inodes? Wait-- never mind; your edit to your question tell me I misunderstood you.) Anyway, the file's existence is known, along with the ironical contention by the Finder that it doesn't exist. Obviously, it does. Here's how to change that:
First, determine the file's inode number. In Terminal.app,
cd
to the directory "folder" and issue this command:ls -i *.mp3
Copy the number string of the inode provided in the left-hand column of the response, which will be something like
12345678 03 - E ̄lusion.mp3
--and put it into this command, which will rename it to something the terminal can render correctly:
find . -inum 12345678 -exec mv {} deletemenow \;
--giving you the file "deletemenow" in the folder "folder," both of which you may dispose of in whatever way best suits your fancy.