[OpenIndiana-discuss] Deleting empty directories

Tim Mooney Tim.Mooney at ndsu.edu
Wed Aug 2 21:32:23 UTC 2023


In regard to: [OpenIndiana-discuss] Deleting empty directories, Michelle...:

> Basically, I extract all the flac files out of my main music
> collection, to a separate location, (using rsync) and then I have to
> delete the empty directories that rsync has created.

You could use '--prune-empty-dirs' with rsync.

> I managed the first part, no problem. However, it's the deleting of
> empty directories that is causing me trouble.
>
> The Linux command is...
> find /mnt/jaguar/users/michelle/FlacCopy -type d -empty -delete
> ...however the OI version of find doesn't support -empty

No, but it supports '-depth', which means you can

 	find /mnt/jaguar/users/michelle/FlacCopy -depth -type d \
 		-exec rmdir {} \; 2>/dev/null

That will fail *a lot*, but the error messages are thrown away and the
empty directories will be deleted.

or if you have GNU fileutils installed (so 'grmdir' exists)

 	find /mnt/jaguar/users/michelle/FlacCopy -depth -type d \
 		-exec grmdir --ignore-fail-on-non-empty {} \;

-depth is important for either of these to work.

The best part of both of those is that you can insert 'echo' between
'-exec' and the start of the command, and it will show you what it's
going to do without doing it.  If you like what you see, just remove the
'echo'.

> I've tried to install gfind, but that doesn't appear to be available.

Someone else already answered with the correct pkg FMRI.

Tim
-- 
Tim Mooney                                             Tim.Mooney at ndsu.edu
Enterprise Computing & Infrastructure /
Division of Information Technology    /                701-231-1076 (Voice)
North Dakota State University, Fargo, ND 58105-5164



More information about the openindiana-discuss mailing list