On 2015-05-25 Mon 11:55 AM |, Philip Guenther wrote: > On Mon, 25 May 2015, Tim Chase wrote: > > On 2015-05-25 09:32, [email protected] wrote: > > > $ mkdir -p /tmp/foo/bar > > > $ ls -dF /tmp/foo/bar > > > /tmp/foo/bar/ > > > $ find /tmp/foo -type d -empty -ls > > > 31751 4 drwx------ 2 craig wheel 512 May 25 09:06 /tmp/foo/bar > > > > > > $ find /tmp/foo -type d -empty -exec rmdir -- {} \; > > > find: /tmp/foo/bar: No such file or directory > > > ^^^^^^^^^^^^^^^^^^^^^^^^^ > > > > Build the list of files/dirs to delete depth-first and it Works For > > Me(TM): > > > > find /tmp/foo -depth -type d -empty -exec rmdir -- {} \; > > That prunes from the bottom up, so it'll also remove directories that only > contain directories that are empty, and so on recursively, which may not > be the goal. > > If the goal is only to remove the empty leaf directories, then use -prune > to tell find to not recurse into the directory you're removing: > > find /tmp/foo -type d -empty -prune -exec rmdir -- {} \; > > > or possibly > > > > find /tmp/foo -depth -mindepth 1 -type d -empty -exec rmdir -- {} \; > > That works, but is dependent on the target hierarchy only being 2 levels > deep, so it's harder to generalize. >
Thanks both for -depth & -prune. I was wondering if it was an async mount thing: $ mount -d /tmp exec: mount_ffs -o rw -o nodev -o nosuid -o noexec -o async /dev/wd0j /tmp In the case of an empty directory, is the 'No such file or directory' message a bug, or just my usage? Cheers. -- Saturday Scottish Spring Higlands Hillwalk - most snow now gone: http://www.WalkHighlands.Co.UK/lochlomond/ben-ledi.shtml
