gpt4 book ai didi

Linux - Bash - 在许多用户目录中应用 chown

转载 作者:太空狗 更新时间:2023-10-29 11:37:23 25 4
gpt4 key购买 nike

我在 /home/ 目录中有大约 400 个用户。

我在 /var/repos/my_repo.git 上有一个 git 存储库

我已经使用 root 帐户通过 bash 命令将此存储库克隆到主文件夹中的所有用户。

现在我想根据每个文件夹为每个用户更改克隆目录的所有者。

类似于:

find . -maxdepth 1 -type d ! -name . -prune -exec chown {}:MY_GROUP {}/www/my_repo.git -R

它不会工作,因为 {} 返回 ./username,所以我只需要一种方法来清理 ./

有人有更好的解决方案吗?

最佳答案

如果您没有正确地递归到子目录,find 在这里只是一个不必要的并发症。

for d in */www/my_repo.git; do
chown -R "${d%%/*}:MY_GROUP "$d"
done

一个更好的方法可能是首先通过 sudo 克隆为目标用户。

为了完整起见,如果你真的想使用 find ,一个稍微丑陋的修复可能是

find . -maxdepth 1 -type d ! -name . -prune -exec sh -c 'chown "${1#./}:MY_GROUP "$1"/www/my_repo.git -R' _ {} \;

关于Linux - Bash - 在许多用户目录中应用 chown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26368757/

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