gpt4 book ai didi

linux - 如何使用 BASH 设置循环以查找具有写权限的目录?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:53:06 24 4
gpt4 key购买 nike

我对 Linux 和 shell 脚本编写还很陌生,我被困在必须编写的脚本的某个部分。这是为了类作业。

我需要编写一个循环来检查是否有用户(在我的组中)使用写入开关 rwx 打开了 public_html 文件。这样我就可以将信息写入其中,然后在获取所需信息后从该组成员的 public_html 中检索它。

这是我现在的位置:

while read temp;do

# this is my main hang up, to see it this global
# switch is turned on to write.
if[[ <9> = 'w' ]]
echo "$temp has their w switch turned on."

# this also is throwing me off, i think this is the way to
# keep going until all the public_html directories in the
# group have been seen.
done < ..public_html

或者我正在尝试弄清楚如何使用 find 命令,它在逻辑上似乎更简单并且更有意义,我只是从未使用过它所以我在这个上有点靠谱我试过这个线无济于事,也许它关闭?

find . */home/public_html -perm -g +w
#I was hoping that would search all user directories looking for the permission +w turned on in public_html.

最佳答案

您需要使用循环来执行此操作吗?这似乎很适合 find .特别是,-perm-gid-type 测试在这里很有用。

您能更详细地解释一下您的环境吗?您是否在用户主目录中查找名为 public_html 的文件?或者您正在寻找当前目录中的文件/文件夹?还是完全不同?

使用find的一些提示:

  • 使用 -type d 测试将结果限制在文件夹中
  • 使用 -name 测试将结果限制为名为“public_html”的内容
  • 使用 -gid 测试将您的结果限制在您组中的事物(id -g 命令应该报告您的组 ID)
  • 使用 -perm -g+w 测试将结果限制为可组写的内容

结合所有这些,您应该能够准确地过滤出您要查找的内容。我链接到的手册页底部有一个“示例”部分,展示了如何使用各种参数。您可能还想查看 this find tutorial更多示例和解释。

关于linux - 如何使用 BASH 设置循环以查找具有写权限的目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15075673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com