Removal script

Karl Denninger karl at denninger.net
Sat Feb 15 13:36:14 UTC 2020


On 2/15/2020 07:31, Jos Chrispijn 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!
>
> /jos

Well, there's no completely "safe" way that might not nuke something you
don't intend, but....

find . -type d -name 'nonsense' -exec rm -rf {} \;

Starts in the current directory, walks the tree, anything that is a
directory and has the name "nonsense" is "rm -rf'd".

Just don't be wrong about any of those directories being or having in
them something you don't want nuked.  "rm -rf" does exactly what you
tell it to and it's entirely possible to really hose yourself with it
(e.g. "rm -rf /" will do exactly what you think it might.)

-- 
Karl Denninger
karl at denninger.net <mailto:karl at denninger.net>
/The Market Ticker/
/[S/MIME encrypted email preferred]/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4897 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20200215/e6eaafed/attachment.bin>


More information about the freebsd-questions mailing list