Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

linux - 如何在Linux中一步更改文件夹及其所有子文件夹和文件的权限? [关闭](How do I change permissions for a folder and all of its subfolders and files in one step in Linux? [closed])

I would like to change permissions of a folder and all its sub folders and files in one step (command) in Linux.

(我想在Linux中一步(命令)更改文件夹及其所有子文件夹和文件的权限。)

I have already tried the below command but it works only for the mentioned folder:

(我已经尝试过以下命令,但它仅适用于上述文件夹:)

chmod 775 /opt/lampp/htdocs

Is there a way to set chmod 755 for /opt/lampp/htdocs and all of its content including subfolders and files?

(有没有办法为/opt/lampp/htdocs设置chmod 755及其所有内容,包括子文件夹和文件?)

Also, in the future, if I create a new folder or file inside htdocs , how can the permissions of that automatically be set to 755 ?

(此外,将来,如果我在htdocs创建一个新的文件夹或文件,它的权限如何自动设置为755 ?)

I had a look at this link too:

(我也看过这个链接:)

http://stackoverflow.com/questions/3740187/how-to-set-default-chmod-in-linux-terminal

(http://stackoverflow.com/questions/3740187/how-to-set-default-chmod-in-linux-terminal)

  ask by Adam translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The other answers are correct, in that chmod -R 755 will set these permissions to all files and subfolders in the tree.

(其他答案是正确的,因为chmod -R 755会将这些权限设置为树中的所有文件和子文件夹。)

But why on earth would you want to ?

(但是为什么你想要呢?)

It might make sense for the directories, but why set the execute bit on all the files?

(它可能对目录有意义,但为什么要在所有文件上设置执行位?)

I suspect what you really want to do is set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find command.

(我怀疑你真正想要做的是将目录设置为755并保留文件或将它们设置为644.为此,您可以使用find命令。)

For example:

(例如:)

To change all the directories to 755 ( drwxr-xr-x ):

(要将所有目录更改为755( drwxr-xr-x ):)

find /opt/lampp/htdocs -type d -exec chmod 755 {} ;

To change all the files to 644 ( -rw-r--r-- ):

(要将所有文件更改为644( -rw-r--r-- ):)

find /opt/lampp/htdocs -type f -exec chmod 644 {} ;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...