• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

changing permissions on every file in a folder

BKLounger

Golden Member
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?
 
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.
 
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] {} \;
 
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 '{}' \;
 
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

 
Back
Top