Troz Troz - 4 months ago 8
Linux Question

Loop through users folders and delete a folder

How can I loop through the

/home
directory for each user and delete a folder? It will be a common one called
/home/$user/.quarentine
.

Answer

Like this:

#!/bin/bash
#Get the list of users
USERS=`ls -l /home|grep "^d"|awk '{print $NF}'`
#Loop for each user and delete the files
for i in $USERS
do
  rm -rf /home/$i/.quarentine
done