On MacOS, I have a bash script where I delete a full directory hierarchy: rm -rf "/mydirectory/here"
Once every 3-4 runs, I go a /mydirectory/here: Directory not empty
And the folder is empty, except a ".DS_Store" file.
I guess that when the rmrf delete files in the directory, MacOS modify the root .DS_Store
in parallel and the rmrf cannot then delete the 'emptied' directory, since the DS_Store appeared again.
Any ideas ?
Asked
Active
Viewed 144 times
0

cyrilchampier
- 2,207
- 1
- 25
- 39
-
1To prevent failure it might work to rename the directory first and remove it after. Or remove write-access before removing, or just remove twice. – Wolph Mar 10 '15 at 09:30
-
@anubhava the problem is different: I do not want to avoid DS_Store creation, this is a shell script committed on a source repository, and I don't have the hand on the executing machine. Could you remove the duplicate tag please ? – cyrilchampier Mar 10 '15 at 09:37
-
Actually solution to your problem is in the question I've linked. Unless you stop this file's auto-creation there will be errors like this in `rm -rf` command. – anubhava Mar 10 '15 at 09:40
-
@anubhava I don't understand, it's not a solution, it's a workaround !? – cyrilchampier Mar 10 '15 at 09:44
-
Since this is default OSX behavior you will get workaround type solutions only – anubhava Mar 10 '15 at 09:47
-
I recently removed 'rm -rf' from a script of mine, after a bug deleted ALL my backup archives for this one app I have. Didn't even notice for months. I'll delete them by hand from now on. .DS_Store is put there by the finder when you open a directory. I'd try rm mydir/.DS_Store; rmdir mydir all in one line. – OsamaBinLogin Sep 08 '22 at 23:24