removing directories

Robert Bonomi bonomi at
Fri Nov 4 20:08:07 UTC 2011

> From owner-freebsd-questions at  Fri Nov  4 12:30:00 2011
> From: Graeme Dargie <arab at>
> To: "freebsd-questions at" <freebsd-questions at>
> Date: Fri, 4 Nov 2011 16:25:26 +0000
> Subject: removing directories
> Ok this might be a bit of a newbie question but here goes.
> I have a large number of directories  around 300 which all have sub dirs, so
> me of those have sub dirs in each of these there are two further sub dirs ca
> lled pages and thumbnails, is there an easy way to remove all the pages and 
> thumbnail dirs from the tree?

Note: _please_ hit the enter key at around column 72, not all mail clients do
smart word-wrap, when confronted with long lines.

There are a number of ways to approach this problem.  

*IF* the 'pages' and 'thumbnails' directories are a 'fixed' number of levels
down from the directory containing those 'around  300' directories, you can
use simple wildcards -- e.g. something like 'rm -fr */*/*/pages'.

A more general approach is to use find(1), something like:
    find . -type d ( -name pages -or -name thumbnails ) -delete
or (if the above complains about 'non-empty' directories
    find . -type d ( -name pages -or -name thumbnails ) -exec rm -fr {} \;

BEWARE: the parens may need to be quoted, to prevent the shell from giving 
them special meaning.

More information about the freebsd-questions mailing list