Change File permissions on numerous files
Hopefully a simple question!
I run a small network at a school consisting of a linux red hat 9 box running squid, samaba, dansguardian, etc. We have a office management program that we use for attendance, grades, family info, etc. Updates for this program come out from time to time and must be installed. So... When I run the update it changes the permissions on all the files in the directory, say /123 What I want to know is how can i change all the files, directories, etc underneath /123 to read/write at the same time without having to go to each file/directory manually and change them? Any help would be appreciated! |
Code:
find /123 -print0 | xargs -0 chmod u+rw |
Quote:
So i better understand what I am doing here: I assume "find /123" will find the directory /123 and the "chmod u+rw" means to change it to read and write for everyone? what does -print0 | xargs -0 chmod u+rw actaully mean? Thanks again for the quick reply and the time saver! |
Hi,
If you want to change all (!) the normal files: find /123 -type f -exec chmod 644 {} \; All the directories and subdirs: find /123 -type d -exec chmod 755 {} \; The -type f (or d) only selects normal files (f) or directories (d). /123 is the starting point, all subdirs are checked too. The -exec ... {} \; part makes it possible to execute a 'normal' command, chmod in this case. Hope this is what you want, try it first on a non essential directory :) |
find /123 will find the directory /123 and all subdirectories and files below
-print0 will print the files with a trailing [00] byte, that's important if you have spaces or strange characters in your filenames | xargs -0 will pipe the file and directory names found, one at a time, to the command specified thereafter chmod u+rw will add read and write the users permissions so it boils down to chmod u+rw /123 chmod u+rw /123/file 1 chmod u+rw /123/file 2 chmod u+rw /123/dir1 chmod u+rw /123/dir1/file 3 and so on |
Thank you to both responders, the future just got easier for me! I did print off obth ways of doing it and will experiement with the one i didnt use at a later time.
Thanks again! With help like this I love Linux |
You could also just use the -R (recursive) flag to chmod (though if you want to limit it to just regular files (or directories), then obviously 'find ... -type ...' is the way to go).
|
I want it to apply to all the files and directories including and under /123 so it would be find /123 -R -exec chmod 755 {} \;
Is that correct? |
You don't need to use find. 'chmod -R 755 /123' suffices, with the advantage that only one instance of chmod is spawned, instead of one for each file.
|
Hi,
I totally agree with soggycornflake: If you want everything changed use chmod not find. |
All times are GMT -5. The time now is 02:20 PM. |