I am entirely new to shell scripts. I know how to change the mode for a single file.
But, I need to meet the following requirement and my operating system is red hat enterprise linux
Like wise im having 10 directories where i need to recursively find all the files in all directories and change the mode to 644.
Expecting your kind assistance to complete this requirement.
Some research points to get you going.
find
command can be used to find files of varying properties under a given point. -type
to select specific file types (regular files, directories, etc). -maxdepth
to restrict how deep it will go down the tree. -perm
to select only files with specific permissions. -print
to output the filenames, including capturing them to a text file for later mailing (with a tool like mailx
). -exec
to carry out arbitrary commands on each file matching the conditions. chmod
is the command to change permissions. For example, the following commands will find all regular files of the form *.dat
, in the current directory (no subdirectories) and with permission 640
, then change all those permissions to 644
:
find . -type f -perm 640 -name '*.dat' -maxdepth 1 -exec chmod 644 {} ';'
All these options, and more, can be found in the manpage for find
with the command:
man find
or by looking for some good explanations, such as the GNU find documentation .
However, find
is not a tool for the faint of heart, it will bite you at every opportunity. Expect to ask at least another ten questions here before you get what you need :-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.