Simon 'corecode' Schubert corecode at
Thu Feb 14 03:09:13 PST 2008

Rahul Siddharthan wrote:
For example, how do you use "find" to find all files in a directory
that end in ".el" and don't have a corresponding ".elc" file?  
 find . -name '*.el' -print  \
    |sed 's/^/FOO=/' \
    |sed 's/$/; if [ ! -f ${FOO}c ]; then echo $FOO; fi/'  \
    | sh

When I want to do something like that to a large directory, I generate
a full directory listing and then write a python program to parse it.
That seems easier to wrap my mind around.  (The author of the above
find command used emacs-lisp instead, then figured out the correct
find incantation because it bothered him.  "It only took me 12 tries
to get it right.  It only spawns two processes per file in the
directory tree we're iterating over.  It's the Unix Way!")
No doubt Simon or someone will now point out a trivial one-line
invocation of find that will do the job and will be obvious to anyone
who understands the find manpages.
I'd go for (if only in the current directory, not subdirs)

for f in *.el
	[ -f "${f}c" ] || echo "$f"
likewise, with find for subdirs (not POSIX):

find . -name '*.el" -exec sh -c 'for f; do [ -f "${f}c" ] || echo "$f"; 
done' dummy {} +

I don't think that shows how awkward unix is.  I bet you could find tasks 
which need much more stupid hacks.

Serve - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /"\
Work - Mac      +++  space for low €€€ NOW!1  +++      Campaign     \ /
Party Enjoy Relax   |      Against  HTML   \
Dude 2c 2 the max   !       Mail + News   / \

More information about the Kernel mailing list