LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What is the maximum length of a command? (https://www.linuxquestions.org/questions/linux-newbie-8/what-is-the-maximum-length-of-a-command-561824/)

c_h_i_ll_a_x 06-14-2007 12:03 PM

What is the maximum length of a command?
 
Hi all,
I am using the following command in my script. But I am not sure if this will break because of the maximum length of command that is allowed in LINUX.

The command I am using is:
rpm -i -v --ignoresize *.rpm

The directory contains more than 2000 rpms. So I guess this will create a long command after evaluation of *.rpm and may break.

Can anyone tell me what is the maximum length of a command?

Thx,
c_h_i_ll_a_x

SciYro 06-14-2007 12:18 PM

I get "broken" commands all the time, nothing will happen, bash will spit out "argument list to long". 2000 arguments dosent sound to bad, about on the border i think. If it does break, all you have to do is break up the command, using "find" together with "xargs" is a good method.

pwc101 06-14-2007 12:58 PM

Or do it in a for loop:
Code:

for i in *.rpm; do rpm -i -v --ignoresize $i; done
That way your argument list is only ever using a single file, but it will still do the whole directory-full.

Note: this is untested, so I might be wrong ! ;)

dawkcid 06-14-2007 02:22 PM

Quote:

Can anyone tell me what is the maximum length of a command?
getconf ARG_MAX

(typically 128K on Linux)

BTW, a for loop will work fine, but execs a new instance of the command for each file. As SciYro mentioned, find | xargs is a more efficient solution.

c_h_i_ll_a_x 06-15-2007 07:22 AM

Hi all,
Thanks for the suggestions but I have one more doubt.

In case of "rpm *.rpm" command if one of the rpms fails to install, does the rpm utility rollback/uninstall all the rpms that are already installed before the failed one (such that if not all rpms are installed then there shouldn't be any). If this is the case then we don't have to do clean-up.

But if I use find and xargs then I have to do clean-up my self for already installed rpms. For example in the below command, rpm will process each rpm separately.
find . -name '*.rpm' | xargs rpm -i -v --ignoresize

-
c_h_i_ll_a_x

dawkcid 06-17-2007 11:24 AM

No, rpm doesn't rollback, each package is effectively processed individually.

chrism01 06-18-2007 02:33 AM

Why don't you use the pkg mgr that comes with your distro, then you won't even have to think about it?
Pls add your distro to your info.

c_h_i_ll_a_x 07-04-2007 09:15 AM

Hi all,
Now I am working on a different approach.

I want to create a new binary that would take a directory as an argument. Internally, this program would collect the list of files and build an RPM transaction and then tell RPM to process the transaction.

But I am not sure how to do this. I have looked into some info on net but couldn't find the right.

Has anyone looked into programming with RPM or how to use rpm.h interface?
Please help...

Tinkster 07-04-2007 01:25 PM

Quote:

Originally Posted by c_h_i_ll_a_x
Hi all,
Thanks for the suggestions but I have one more doubt.

No, you don't. You have a question.
There's a reason this place is called Linuxquestions,
not Linuxdoubts.




Cheers,
Tink


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