change file permissions recursivly without changing permission of directories
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
change file permissions recursivly without changing permission of directories
i'm not sure wether this does work or if it's even supposed to but i've got the following problem. i have lot's of files in many directories and in a quite deep directory tree. so now i tried to do the following: chmod 644 * -R. the outcome is that chmod changes the privileges of the first directories first and that it takes itself the permission to write into those directories any changes and therefore can't change the file's permissions. any ideas how to do this? i'm lost.
checking the chmod man page looks like there is no straight forward way to do this.
I came up with a couple of solutions.
you can use the find tool to list all regular files (assuming you are trying to chmod regular files, you can use it to find device files if thats what you want), and use the output as the argument list of chmod like this
chmod 664 `find foo/ -type f `
yopu know about using ` foo` to insert the standard output in the argument list right??
the only problem is if you try to do this for very large directories /usr/local or something chmod will complain about too many arguments.
another solution is to use gawk to produce a the commands on the fly like this:
find foo/ -type f | awk '{print "chmod 664 " $0}' | sh
this will add the string 'chmod 664 ' to every entry of the find output and then pass it to the shell to execute.
I don't think there is a limit to how big this can be, but in case it is too big then redirect the output to a file and use it as a shell script instead this way
I think foo/ was just an example. Replace it with the name of directory on which you want to run chmod. So if you want to change the perms of all files in /usr/share, you will try something like chmod a+r `find /usr/share -type -f `. Again, replace a+r with whatever permissions you want to give.
--Sarin
( Also, don't try it on system directories. It might cause some problems. /usr is again an example, though it will really work )
anyway you should learn you foos and fubars since they are very widly used in the GNU/Linux and Unix world.
any hypothetical file/command/user/etc. is called foo, any hypothetical file/command/user/etc in an error sitiuation (in an example of what you shouldn't do for instance) is called fubar or foobar
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.