Removal script

Steve O'Hara-Smith steve at sohara.org
Sat Feb 15 13:42:08 UTC 2020


On Sat, 15 Feb 2020 14:31:59 +0100
Jos Chrispijn <bsduser at cloudzeeland.nl> wrote:

> I am looking for a way to remove a nested subdirectory in a directory.
> 
> Example:
> directory /mysources has a certain number of subdirectories which 
> contain subdirectory 'nonsense' in various subdirectories, which contain 
> also subdirectory 'nonsense', etc.
> 
> What I would like to do is that the script removes all 'nonsense' 
> folders in the base /mysources.
> Can you pls tell me how I can do that savest? Thanks!

	
	If the nonesense directories are not empty and you want them gone
complete with contents then:

	find /mysources -name nonesense -type d -depth -exec rm -rf {} \;

If they're empty then:

	find /mysources -name nonesense -type d -delete

-- 
Steve O'Hara-Smith <steve at sohara.org>


More information about the freebsd-questions mailing list