[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: chmod + chown
On Monday, March 29, 2004, at 02:03 PM, john doe wrote:
> is there any way to do a recursive chmod where it only modifies the
> file if it has a certain owner and group? i dont want to have to
> resort to shell scripting if i dont have to
In the simplest case, find traverses a filesystem tree and prints all
the "files" (files, directories, devices, fifos, etc.) For example:
You can also specify a folder or list of folders. For example, to
traverse both /etc, /var, and the current directory:
$ find /etc /var .
You can also specify a test condition. That is, if a "file" passes a
test, it will get listed. For example, to find only regular files (not
directories nor devices nor fifos) in the directory tree rooted in the
$ find . -type f
You can also specify a series of test conditions. Those tests will be
AND'ed by default. For example, you want to find all files that are
owned by me:
$ find . -type f -user rwcitek
Lastly, since the output is a list of files, you can pipe it to other
programs. For example, to change the permissions to 0700 on all files
owned by me:
$ find . -type f -user rwcitek | xargs chmod 0700
Find comes with a whole bunch of other goodies, including operators,
options, tests, and actions. You can even do grouping. For a brief
listing type 'find --help' For a more detailed description of options,
see 'man find'
> i can with chown, which rocks, but i would like to be able to do it
> with chmod.
> also is there an easy way to do something like chmod 754 for
> directories but 755 for files? (not necessarily those 2 sets of
> permissions, but one set of permission bits for folders and another
> for files. that is more what i am after
Yes. This is exactly what find is for:
$ find . -type d -print0 | xargs -0 chmod 0754
$ find . -type f -print0 | xargs -0 chmod 0755
The -print0 option in find and the -0 option in xargs properly handles
filenames that have spaces in them.
Let us know what you decided to do and how things worked out for you.
To unsubscribe, send email to email@example.com with
"unsubscribe silug-discuss" in the body.