I've just caught a confusing error:
rm: cannot remove `xxx/app/cache/prod': Directory not empty
which was caused by the following command:
rm -rf $cache_dir/*
where $cache_dir
is defined as xxx/app/cache
So I see it like: rm
removed everything in cache/prod
dir, then right before it attempted to remove the cache/prod
directory - another program created a file/a directory inside it thus it caused rm
failure.
Is my assumption correct?
rm -r
is not atomic. If you want to be sure that no more files get created in the directory while therm -rf
is running, you could rename it first, then remove the renamed directory. – Johnny Oct 22 '13 at 00:19rm -rf
being thread safe: if you run it multiple times concurrently on the same directory, the directory get deleted. This is aboutrm -r
not being atomic. – Gilles 'SO- stop being evil' Oct 22 '13 at 22:47rm
invocation, we may speak about thread-safety. But anyway, it doesn't change anything – zerkms Oct 22 '13 at 23:36rm -rf
is thread-safe:rm -rf & rm -rf
works as expected. The combination ofrm -rf
and file creation isn't thread-safe. – Gilles 'SO- stop being evil' Oct 23 '13 at 02:32