LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-04-2012, 01:07 AM   #1
sluge
Member
 
Registered: Dec 2006
Location: Russia,52
Posts: 128

Rep: Reputation: 6
Question 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?
 
Old 12-04-2012, 01:47 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
1 members found this post helpful.
Old 12-04-2012, 01:49 AM   #3
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
It's not a bash limit but you can get the E2BIG error from the execve call.
 
Old 12-05-2012, 07:54 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] vncviewer command line for view size? dokie80 SUSE / openSUSE 9 08-10-2010 10:05 AM
Increase the command line buffer size Akiles Linux - General 3 04-19-2005 11:17 AM
changing text size on command line anvilmonkey Linux - Software 1 03-21-2005 03:40 PM
command line font size poiuytrewq Linux - Newbie 8 09-21-2004 02:57 AM
Command Line Screen Size bgfay Linux - Newbie 2 06-22-2004 08:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration