changing permissions on every file in a folder

BKLounger

Golden Member
Mar 29, 2006
1,098
0
0
So i've copied about 2,000 files onto my ubuntu 8.04 machine from a windows machine but now whenever anybody on the network goes to access them they can see the file name but can't runs the files. I checked the permissions and the problem is permissions for group and others is none. I know I can do this one by one in the gui and i know how to do it for one file at a time via command line but how can i go about changing the permissions on all 2000+ files to allow groups and others read access?
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
For the record, in case anyone searches for this problem in the future, I will answer it.

chgrp -R group /path/to/folder will set the group on a folder and all subfolders and files
chmod -R permissions /path/to/folder will do the same for permissions.

chown is done the same way and can be used to set users and groups.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
For nasty versions of chgrp, chmod, and chown that don't allow the useful -R function:
find /path/to/folder -type f -exec chmod [permissions] {} \;
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: sourceninja
For the record, in case anyone searches for this problem in the future, I will answer it.

chgrp -R group /path/to/folder will set the group on a folder and all subfolders and files
chmod -R permissions /path/to/folder will do the same for permissions.

chown is done the same way and can be used to set users and groups.

Originally posted by: degibson
For nasty versions of chgrp, chmod, and chown that don't allow the useful -R function:
find /path/to/folder -type f -exec chmod [permissions] {} \;

If I'm setting the permissions using octals (eg 755, as opposed to g+w for example) then it's usually going to work better using the 'find' method. this is because you will typically want different permissions on your folders than you do on your files. Sometimes, even when using mode operators (eg g+w), you may want it to apply only to files or only to directories, in which cases the find method works well here, too.

For example, say you want everthing to be user writeable and group and world readable. If you just did 'chmod -R 644 /path/to/folder' than your directories would be inaccessible without the execute bit set. Likewise, if you do 'chmod -R 755 /path/to/folder' than all your files have the execute bit set and could be a security risk.

So for this case I would set permissions like this (run both lines):
chmod -R 644 /path/to/folder
find /path/to/folder -type d -exec chmod 755 '{}' \;
 

QuixoticOne

Golden Member
Nov 4, 2005
1,855
0
0
Use null terminations / delimiters if your paths/files may include spaces.

find /somewhere -type f -print0 | xargs -0 chmod 444
find /somewhere -type d -print0 | xargs -0 chmod 555

And a nice way to check sets of stored files for subsequent accidental corruptions / deletions....
find /somewhere -type f -print0 | xargs -0 md5sum > /somewhere/files.md5s
md5sum --check < /somewhere/files.md5s