Filemanagement

G. Matthew Rice matt-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org
Sun Mar 7 21:35:30 UTC 2004


Fraser Campbell <fraser-eicrhRFjby5dCsDujFhwbypxlwaOVQ5f at public.gmane.org> writes:
> >         find . -name '*.pgn' | xargs cat >target.file
> 
> If I'm going to run into problems with to many files I usually handle it
> this way:
> 
>     TARGET=dest_dir/big_file.pgn
>     find source_dir/ -name '*.pgn' | while read file; do
>         cat "$file" > $TARGET
>     done
> 
> Not saying it's the best way but at least it handles spaces in filenames 
> properly (something Windows users seem to love).

That's true.  Add that to a caveat for my 'find | xargs' example.  In your
above example, you'd need to truncate/rm+touch [or one of many other ways]
the $TARGET file first and use '>>' in the loop.

If you wanted to worry about spaces in files, you could run cat on each file
with find's '-exec' option.  Or better, use the 'find -print0/xargs -0'
combination:

        find . -name '*.pgn' -print0 | xargs -0 cat >target.file

For example:

  matt-aNH4h1Gy6+c at public.gmane.org tmp]$ ls -l *.pgn
  -rw-rw-r--    1 matt     matt            2 Mar  7 16:32 a.pgn
  -rw-rw-r--    1 matt     matt            2 Mar  7 16:32 b.pgn
  -rw-rw-r--    1 matt     matt            2 Mar  7 16:32 c.pgn
  -rw-rw-r--    1 matt     matt            2 Mar  7 16:40 d space.pgn
  [matt-aNH4h1Gy6+c at public.gmane.org tmp]$ find . -name '*.pgn' -print0 | xargs -0 cat
  a
  b
  c
  d
  [matt-aNH4h1Gy6+c at public.gmane.org tmp]$

Y'know, I bet the guy's shell could handle all of the files with one cat
command :)  Especially if he just did a cd into that directory first.

HTH,
-- 
g. matthew rice <matt-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org>                            starnix inc.
phone: 905-771-0017 x242                        thornhill, ontario, canada
http://www.starnix.com              professional linux services & products
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list