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
.
Asked
Active
Viewed 180 times
2 Answers
1
In a single line:
for user in $(ls /home); do rm -Rf /home/${user}/.quarentine; done

thirafael
- 5
- 2
-
better say `for user in /home/*`. [It is not good to parse the output of `ls`](http://mywiki.wooledge.org/ParsingLs) – fedorqui Aug 08 '16 at 09:07
0
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

AwkMan
- 670
- 6
- 18
-
it is not a good idea to parse the output of ls (see the link in the other answer). Better use a simple loop, like thirafael did. – fedorqui Aug 08 '16 at 09:18