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

Karl Lattimer karl at qdh.org.uk
Fri Jul 16 08:23:19 UTC 2010


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





More information about the Kent mailing list