Berkeley CSUA MOTD:Entry 24838
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/25 [General] UID:1000 Activity:popular
5/25    

2002/5/15 [Computer/SW/Languages/Perl] UID:24838 Activity:very high
5/15    How do you use find and xargs together (correctly) if your find doesn't
        support -print0?
        \_ perl! perl! perl is the STANDARD! ...find parser.
        \_ In Bourne shell you can try omething like this:
           find . -name '*.java' > .files
           cat .files | \
           while read LINE ;
           do
               echo rm -f "'$FILE'" ;
           done
           Note this is much slower than xargs, but it is the only
           reliable way. It is also more reliable than -exec since
           not all find's understand quoting properly for -exec.
           Note that this is much slower than xargs, but it is the
           only reliable way. It is also more reliable than -exec
           since not all find's handle quoting properly for -exec.
        \_ find . -name '*.java' |xargs rm -f
           equivalent to:
           rm -f `find . -name '*.java'`
           \_ I know, but that doesn't really help me much.
              find . -name "*pl" | xargs file
              won't work if a pl file has a space in it.
              find . -name "*pl" -print0 | xargs -0 file
              works but I don't have the -print0 option on my Solaris box.
                \_ how about find . -name '*pl' |sed -e 's/\ /\\/g'|xargs ...
                   \_ Other characters like ' would also ahve to be removed.
              \_ Install gnu find on your box.
           \_ No it is not. Command expansion (``) is limited by MAXARGS.
              If your `` expand to more than MAXARGS words, then command
              expansion will fail. xargs makes sure that it never invokes
              a command with more than MAXARGS arguments so it always
              works.