how to do Batch Operations with chmod

10:58 AM
Doing Batch Operations with chmod


You need to set permissions on all the files or a directory, or on batches of files.


chmod supports operating on lists of files. You can also use find or shell wildcards to generate a list.


To make several files read-only for everyone, you can use chmod as follows:


$ chmod 444 file.txt file2.txt file3.txt




To make all files in the current directory readable/writable, for the file owner and group, without changing the directory permissions, use:




$ find . -type f -exec chmod -v 660 { } \;




You can also change all files belonging to a particular user. This example starts at the root of the filesystem:


$ find / -user terri -exec chmod -v 660 { } \;




You can set permissions for a directory and its contents, including subdirectories, with the -R (recursive) flag:


$ chmod -R -v 755 /shared




This example makes all the .txt files in the current directory readable/writable to the owner, and world-readable:


$ chmod -v 644 *.txt




To change all files in the current directory that begin with your chosen string, use:


$ chmod -v 644 apt*

0 Comments