【问题标题】:Loop through users folders and delete a folder遍历用户文件夹并删除文件夹
【发布时间】:2016-08-08 17:06:10
【问题描述】:

如何循环遍历每个用户的 /home 目录并删除文件夹?这将是一个常见的称为/home/$user/.quarentine。

【问题讨论】:

    标签: linux centos6


    【解决方案1】:

    在一行中:

    for user in $(ls /home); do rm -Rf /home/${user}/.quarentine; done
    

    【讨论】:

    【解决方案2】:

    像这样:

    #!/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
    

    【讨论】:

    • 解析 ls 的输出不是一个好主意(参见另一个答案中的链接)。最好使用简单的循环,就像 thirafael 所做的那样。
    猜你喜欢
    • 1970-01-01
    • 2010-11-25
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    相关资源
    最近更新 更多