[H-GEN] Useful not so obvious tips

Michael Anthon michael at anthon.net
Mon Oct 25 07:06:08 EDT 2004


ben.carlyle at invensys.com wrote:

>filename as a parameter. xargs will hand a "reasonable" number of 
>parameters to each execution, while keeping in mind limits on the length 
>of the command line for overly-long filenames. It can be more efficient. 
>  
>
That's what the -l option is for..  The -i option is also fairly useful 
although not so much when the source of the data is find since it 
provides basically the same function as "find ... -exec ... "

Some simple examples (also showing Greg's suggestions of -print0 and -0)

belial:~# find . -name file\* -maxdepth 1
./files.txt
./file with spaces

belial:~# find . -name file\* -maxdepth 1 | xargs ls
ls: ./file: No such file or directory
ls: with: No such file or directory
ls: spaces: No such file or directory
./files.txt

Oops...

belial:~# find . -name file\* -print0 -maxdepth 1 | xargs -0 ls
./file with spaces  ./files.txt

That's better...

belial:~# find . -name file\* -print0 -maxdepth 1 | xargs -0 -i ls {}
./files.txt
./file with spaces

Does them one at a time (useful is the program only takes one argument)

Cheers,
Michael




More information about the General mailing list