macos 在mac中使用shell命令递归更改文件和文件夹的权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3834526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
changing permission for files and folder recursively using shell command in mac
提问by pytho
In Linux we can use the following command to change permission mode of the files and folders recursively.
在 Linux 中,我们可以使用以下命令递归更改文件和文件夹的权限模式。
find "/Users/Test/Desktop/PATH" -exec * chmod 777 {} \;
找到“/Users/Test/Desktop/PATH”-exec * chmod 777 {} \;
how could i do the same for mac as i m getting the following error repeatatively.
我怎么能对 mac 做同样的事情,因为我反复收到以下错误。
find: TEST_FILE: No such file or directory
查找:TEST_FILE:没有那个文件或目录
回答by Adam Rosenfield
The issue is that the *
is getting interpreted by your shell and is expanding to a file named TEST_FILE
that happens to be in your current working directory, so you're telling find
to execute the command named TEST_FILE
which doesn't exist. I'm not sure what you're trying to accomplish with that *
, you should just remove it.
问题是*
您的 shell 正在解释它,并扩展到一个名为的文件,该文件TEST_FILE
恰好位于您当前的工作目录中,因此您告诉find
执行名为的命令TEST_FILE
,该命令不存在。我不确定你想用它来完成什么*
,你应该删除它。
Furthermore, you should use the idiom -exec program '{}' \+
instead of -exec program '{}' \;
so that find
doesn't fork a new process for each file. With ;
, a new process is forked for each file, whereas with +
, it only forks one process and passes all of the files on a single command line, which for simple programs like chmod
is much more efficient.
此外,您应该使用习惯用法-exec program '{}' \+
而不是-exec program '{}' \;
这样,这样find
就不会为每个文件分叉一个新进程。使用;
,为每个文件分叉一个新进程,而使用+
,它只分叉一个进程并在单个命令行上传递所有文件,这对于简单的程序chmod
来说效率更高。
Lastly, chmod
can do recursive changes on its own with the -R
flag, so unless you need to search for specific files, just do this:
最后,chmod
可以使用-R
标志自行进行递归更改,因此除非您需要搜索特定文件,否则只需执行以下操作:
chmod -R 777 /Users/Test/Desktop/PATH
回答by Andrew Vit
You can just use the -R (recursive) flag.
您可以只使用 -R(递归)标志。
chmod -R 777 /Users/Test/Desktop/PATH
回答by Einlanzer
By using CHMOD yes:
通过使用 CHMOD 是:
For Recursive file:
对于递归文件:
chmod -R 777 foldername or pathname
For non recursive:
对于非递归:
chmod 777 foldername or pathname
回答by frederickjh
I do not have a Mac OSx machine to test this on but in bash on Linux I use something like the following to chmod only directories:
我没有 Mac OSx 机器来测试这个,但在 Linux 上的 bash 中,我使用类似以下的东西来仅对目录进行 chmod:
find . -type d -exec chmod 755 {} \+
but this also does the same thing:
但这也做同样的事情:
chmod 755 `find . -type d`
and so does this:
这样做也是如此:
chmod 755 $(find . -type d)
The last two are using different forms of subcommands. The first is using backticks (older and depreciated) and the other the $()subcommand syntax.
最后两个使用不同形式的子命令。第一个是使用反引号(旧的和折旧的),另一个是$()子命令语法。
So I think in your case that the following will do what you want.
所以我认为在你的情况下,以下将做你想做的。
chmod 777 $(find "/Users/Test/Desktop/PATH")
回答by Waleed Muaz
IF they Give Path Directory Error!
如果他们给出路径目录错误!
In MAC Then Go to Folder Get Infoand Open Storage and Permissionchange to privilegesRead To Write
在 MAC 然后转到文件夹获取信息并打开存储和权限更改为读写权限