bug-fileutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: better chmod


From: Bob Proulx
Subject: Re: better chmod
Date: Mon, 25 Mar 2002 21:36:53 -0700

> The feature is in two new parametres -D --dirsonly and -F --filesonly when
> you want to change mods recursively only to files or only to directoris.
> (because of changing +x mode to directories by using chmod -R 755 . makes me
> angry, because +x mode will be changed on files too.) Making scripts
> find-based makes me dizzy.

First off thank you for submitting code.  It is most appreciated when
people take the time to create a code patch.

However, I do not think that this functionality is needed or desired
in chmod for two reasons.  For one the X option already does exactly
what you are asking for.  Here is an example.

  chmod -R a+rX dir

This recursively makes all files and directories readable and all
directories searchable.  Which sounds exactly like what you are
proposing but in a standard and portable manor.  This is documented in
the "Conditional Executability" section of the info manual for chmod.
Use 'info chmod' to access the manual.

Secondly people frequently wonder why cat, chgrp, chmod, chown, ls,
mv, rmdir, rm, touch, do not support 'find' command type of
operations.  This is part of the subtle but beautiful design of the
UNIX system.  Programs should be simple and modular.  Common behavior
should be modularized into a common location where it can be used by
other programs.  More complicated programs are created by chaining
together simpler programs.

If every program implemented its own version of file finding then
every command would implement it differently and with its own set of
bugs and unique behavior.  This would lead to many bugs and much code
bloat.  This is already true of the number of different ways to
specify -r or -R and other similar behaviors.  It is much better to
modularize the problem and provide a file recursion mechanism that is
outside of any particular program but then common to all of them.
Here are various examples using find.  The 'find' command is very
powerful and I encourage you to look into it.

Although your particular example does not need find it could be
implemented with find using the first of the following.  But find can
also be used in other ways with other programs.  Here are a few random
examples.  This is why file finding should be left as a common feature
of all programs by being outside of them all.  This is just off the
top of my head.

  find . -type d | xargs chmod a+rx
  find . -name README | xargs chmod 0644
  find . -type f | xargs chgrp other
  find . -name '*.pl' | xargs ls -ld
  find . -name '*.html' | xargs grep foo

When people find that particular combinations of commands are ones
that they use a lot then they will typically create a shell script, a
shell function or a shell alias which does this with a shorter name.
I like shell scripts because they are easier to pass around.

  #!/bin/sh
  find "$@" -name README -print0 | xargs -0 ls -ld

You could call it whatever you desired.  For all intents and purposes
it would be just like a normal UNIX command and its output could be
piped into other commands.  The modularity and the building up of a
more powerful command from smaller commands is in the unix philosophy.

HTH
Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]