Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Force the Finder to show text file previews' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Force the Finder to show text file previews
Authored by: tim_bissell on May 13, '03 06:54:37AM

> Also, if you want to process all sorts of files at once you could do like so:

find ~/ -type f \( -name '*.xml' -o -name '*.html' -o '*.php' \) -exec /Developer/Tools/SetFile -t {} \;

One problem with this command is that the SetFile is executed once for each file matched; this can result in thousands of processes being created, run and stopped. Of course the Unix gods thought of this, so they wrote the wonderful 'xargs' command:

find ~ -type f \( -name '*.xml' -o -name '*.html' -o '*.php' | xargs SetFile -t

xargs works with commands which expect a list of (file)names at the end of their argument list. It reads a list of names from its standard input, and constructs a command (based on the arguments given to it) with a list of names read from standard input. When the command being built reaches the maximum size, it executes it, then if there are any more names on the input, it starts building a new command.
'man xargs' on the command line gives a clearer description of it.

[ Reply to This | # ]
xargs --thanks!
Authored by: das_2099 on May 13, '03 11:11:09AM

Awesome! I never lookd at xargs before...thanks for the rather concise , very usefull hint!

[ Reply to This | # ]
xargs --thanks!
Authored by: tim_bissell on May 14, '03 05:35:19AM


I forgot to add a couple of useful options; MacOS X files and directories tend to have spaces in them, so you should use:

find .... -print0 | xargs -0 ....

instead of

find ... | xargs ...

(note those are zeros, not capital 'O's)

[ Reply to This | # ]