[H-GEN] Useful not so obvious tips

David de Groot david-humbug at viking.org.au
Mon Oct 25 02:03:12 EDT 2004


(third time's a charm - maybe this time I'll get my sending address right)

Anthony Irwin wrote:

>
> It would be good to see if anyone else has some useful tips as I know 
> there are a lot of knowledge in the humbug group.
>
One of my favourites, is the -exec option to find.

Just say you want to do something to all the files in a directory tree, 
but not the directories:

find . -type f -exec do_something_interesting {} \;

Would execute the command do_something_interesting  on each file it 
comes across (specified by {}) and the -type f states only files are 
acted on.  (-type d   would be for directories).

So for instance, if you were on a system that had a brain-dead chmod 
that didn't support the -R  recursive option, and you wanted to make all 
files, owner and group rw and not readable to everyone else, you could do:

find -type f -exec chmod 660 {} \;

This is still useful on systems with a chmod that knows about -R since 
chmod won't differentiate between files and directories, but the above 
find will.

Dave





More information about the General mailing list