Bash example

Hal Burgiss hal at burgiss.net
Thu Aug 20 22:58:53 UTC 2009


On Fri, Aug 21, 2009 at 12:52:48AM +0200, Vincent Arnoux wrote:
> >> I would like an example bash script that checks to see if a directory
> >> exists. If it does, then remove it.
> > Actually, if many dirs exist, remove em all.
> 
> Just remove them, if they don't exist, no error will be raised:
> #! /bin/bash
> 
> rm -fr mydir1 mydir2

find -type d -name $dir -exec rm -fr "{}" \;

That's fairly non-forgiving. It would be best to run the same command without
the rm first to make sure you get what you want.

-- 
Hal




More information about the ubuntu-users mailing list