Perhaps something like this? This should provide the following guarantees for zf_mkdir -p: - If it succeeds, the directory must have existed at some point during the execution of the function (either created by zf_mkdir itself or by some other concurrent process). - If it fails, there must have been a point in time during the execution of the function where the target directory or one of its parents didn't exist and it was impossible to create it. `zf_mkdir -p foo` It should work as expected in the face of concurrent `mkdir foo && rmdir foo` or `touch foo && rm foo`. I confess that I haven't tested it. Roman.