LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   What is the size of command line (https://www.linuxquestions.org/questions/linux-software-2/what-is-the-size-of-command-line-4175439914/)

sluge 12-04-2012 01:07 AM

What is the size of command line
 
Hello!

I want to install all rpms from folder using command:

rpm -i `ls packages`

but my friend said that output from ls command can be very long and it can overflow bash buffers.
What is the size of bash command line?

druuna 12-04-2012 01:47 AM

I do believe you are looking for this:
Code:

$ xargs --show-limits
Your environment variables take up 2762 bytes
POSIX upper limit on argument length (this system): 2092342
POSIX smallest allowable upper limit on argument length (all systems): 4096
Maximum length of command we could actually use: 2089580
Size of command buffer we are actually using: 131072
<ctrl-c>

# or, little less accurate
$ getconf ARG_MAX
2097152

# or, previous command made accurate
$ echo $(( $(getconf ARG_MAX) - $(env | wc -c) ))
2094392

All 3 show the maximum character length of arguments.

linosaurusroot 12-04-2012 01:49 AM

It's not a bash limit but you can get the E2BIG error from the execve call.

David the H. 12-05-2012 07:54 PM

In any case, the use of ls here is not only unnecessary, but also wrong. The proper way to run the command is with a simple globbing pattern.

Code:

rpm -i *.rpm
If you need to avoid the max argument limit, you can do store the files in an array first, and loop over them.

Code:

rpmarray=( *.rpm )

for (( i=0; i<${#rpmarray[*]}; i+=25 )); do
        rpm -i ${rpmarray[@]:i:25}"
done

This will loop over all the files, processing 25 at a time.

I ran a quick test of the above on the entire content of my /etc directory, and it had no problems.

Do note though that the above relies on several bash extensions, and won't work properly in a posix-only shell. You'll have to use find and/or xargs if that's necessary.


See here for more on shell limits:
I'm getting "Argument list too long". How can I process a large list in chunks?
http://mywiki.wooledge.org/BashFAQ/095


All times are GMT -5. The time now is 02:28 PM.