Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 循环浏览用户文件夹并删除文件夹_Linux_Centos6 - Fatal编程技术网

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那样。