在Mac中使用Shell命令以递归方式更改文件和文件夹的权限 [英] changing permission for files and folder recursively using shell command in mac

查看:957
本文介绍了在Mac中使用Shell命令以递归方式更改文件和文件夹的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux中,我们可以使用以下命令来递归地更改文件和文件夹的权限模式.

In Linux we can use the following command to change permission mode of the files and folders recursively.

找到"/Users/Test/Desktop/PATH" -exec * chmod 777 {} \;

find "/Users/Test/Desktop/PATH" -exec * chmod 777 {} \;

我如何在Mac上做同样的事情,因为我反复遇到以下错误.

how could i do the same for mac as i m getting the following error repeatatively.

查找:TEST_FILE:没有这样的文件或 目录

find: TEST_FILE: No such file or directory

推荐答案

问题是*正在由您的Shell解释,并且正在扩展为恰好在您当前工作目录中的名为TEST_FILE的文件,所以您要告诉find执行不存在的名为TEST_FILE的命令.我不确定您要使用该*完成什么,您应该删除它.

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.

此外,您应该使用习惯用法-exec program '{}' \+而不是-exec program '{}' \;,以便find不会为每个文件派生一个新进程.使用;,将为每个文件创建一个新进程,而使用+,它将仅派生一个进程并在单个命令行中传递所有文件,对于像chmod这样的简单程序,效率更高.

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.

最后,chmod可以使用-R标志自行进行递归更改,因此除非您需要搜索特定文件,否则只需执行以下操作:

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 777 /Users/Test/Desktop/PATH

这篇关于在Mac中使用Shell命令以递归方式更改文件和文件夹的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆