Front | Info | Lists | Newsfeeds | Study Guide | What is BSD? |
|
This is the BSDA Study Guide Book written via a wiki collaboration. This is a work in progress. You may contribute to or discuss this specific page at http://bsdwiki.reedmedia.net/wiki/Overcome_command_line_length_limitations.html. Overcome command line length limitationsConceptThe command line length is limited, and often a command should be applied to more arguments than fit on a command line. Understand how to run the command multiple times with different arguments for each call using xargs(1) or a shell "while" read loop. IntroductionThe shell has a limit for the command line length and the system has a limit on how many bytes can be used for the arguments (and environment variables) when starting a new process. (Some shells also have a limit on the command line length saved in its history.) NOTES: TODO: Just briefly mention the following, but focus on generic skills of using xargs and sh while loop instead of adjusting the more advanced tunables. ksh 1024 on command line tcsh 8190 on command line tcsh history is 4096 On DragonFly: TODO: sh has "abort" or "segmentation fault" and exits noticed with around 1920 characters -- report this bug or commit fix NCARGS on FreeBSD and DragonFly is 65536. On OpenBSD and NetBSD it is 262144 TODO: mention "getconf ARG_MAX"?? TODO: do all BSD's have kern.argmax? Common error message is "Argument list too long." TODO: some xargs have -J option for replacements, but I probably won't cover that here and will use "while" instead TODO: mention find -print0 and xargs -0 TODO: example using Bourne style shell:
TODO: do real example above ExamplesThe following is an example of having too many arguments:
A work-around for this is to use shell built-in "echo" and pipe the output to "xargs", for example:
(Note that that output is not shown here, because it was over 15,000 lines.) Practice Exercisesrun a command multiple times with different arguments for each call: ls | xargs md5 (spits out an md5 hash for each file in a dir) More informationxargs(1), find(1)
|