Linux 循环浏览用户文件夹并删除文件夹
如何循环浏览每个用户的Linux 循环浏览用户文件夹并删除文件夹,linux,centos6,Linux,Centos6,如何循环浏览每个用户的/home目录并删除文件夹?它将是一个名为/home/$user/.quarentine的常见文件,如下所示: #!/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 在一行中
/home
目录并删除文件夹?它将是一个名为/home/$user/.quarentine
的常见文件,如下所示:
#!/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
在一行中:
for user in $(ls /home); do rm -Rf /home/${user}/.quarentine; done
最好在/home/*中为用户说
。解析ls的输出不是一个好主意(参见另一个答案中的链接)。最好使用一个简单的循环,就像thirafael那样。