[Klug-general] Bash script to delete folders if they exists

Nathan Friend nathan.friend at gmail.com
Fri Jul 16 08:43:04 UTC 2010


Thanks Karl that was easy.

if [ -d /home/nathan/test2/123 ]
then
rm -r 123
echo "123 deleted"
else
echo "123 not found"
fi

if [ -d /home/nathan/test2/456 ]
then
rm -r 456
echo "456 deleted"
else
echo "456 not found"
fi

Cheers,

Nathan.

On Fri, Jul 16, 2010 at 9:23 AM, Karl Lattimer <karl at qdh.org.uk> wrote:

> On Fri, 2010-07-16 at 09:17 +0100, Nathan Friend wrote:
> > Morning,
> > I would like a simple bash script to check if a list of user
> > directories exist and if they do delete them.  If they don't output a
> > message and skip to next folder to check.  E.g.
> >
> > Does /Home/user1 exist > Yes > Delete /home/user1 goto next check
> >                                        No  > "user1 not found" go to
> > next check
> > Does /Home/user2 exist > Yes > Delete home/user2 goto next check
> >                                        No > "user2 not found" go to
> > next check
> > end.
> >
> > Any ideas how I can do this?
>
> if [ -d /path/to/dir ]
> then
> echo "exists"
> fi
>
> K,
>
> >
> > Cheers,
> >
> > Nathan.
> >
> > _______________________________________________
> > Kent mailing list
> > Kent at mailman.lug.org.uk
> > https://mailman.lug.org.uk/mailman/listinfo/kent
>
>
>
> _______________________________________________
> Kent mailing list
> Kent at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/kent
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/kent/attachments/20100716/cad71499/attachment.htm>


More information about the Kent mailing list