LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Change File permissions on numerous files (https://www.linuxquestions.org/questions/linux-general-1/change-file-permissions-on-numerous-files-497903/)

ryanzietlow 11-02-2006 10:03 AM

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!

uselpa 11-02-2006 10:06 AM

Code:

find /123 -print0 | xargs -0 chmod u+rw
That will include /123 itself.

ryanzietlow 11-02-2006 10:10 AM

Quote:

Originally Posted by uselpa
Code:

find /123 -print0 | xargs -0 chmod u+rw
That will include /123 itself.


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!

druuna 11-02-2006 10:12 AM

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 :)

uselpa 11-02-2006 10:23 AM

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

ryanzietlow 11-02-2006 04:44 PM

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

soggycornflake 11-03-2006 11:55 AM

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).

ryanzietlow 11-03-2006 04:10 PM

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?

soggycornflake 11-03-2006 04:27 PM

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.

druuna 11-03-2006 04:43 PM

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.