Operating System - HP-UX
1753614 Members
6141 Online
108797 Solutions
New Discussion юеВ

Re: Will 'xargs' help on "parameter list too long"?

 
SOLVED
Go to solution
Rob_132
Regular Advisor

Will 'xargs' help on "parameter list too long"?

I need to

ls dir/*o

such that the output is

dir/file1.o
dir/file2.o

But, if there are too many files in the directory, I get the "parameter list too long" error message.

I believe that I can still get the desired output (shown above) when there are too many files - using the 'xargs' command - but am unclear on the syntax.

Help on this would be most appreciated!

Thanks in advance.
11 REPLIES 11
Steven E. Protter
Exalted Contributor

Re: Will 'xargs' help on "parameter list too long"?

I don't know a lot about this, but I'm attaching an example that might prove useful.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Stefan Farrelly
Honored Contributor

Re: Will 'xargs' help on "parameter list too long"?

yes, xargs will do it. simply do;

ls dir/*o | xargs

Im from Palmerston North, New Zealand, but somehow ended up in London...
G. Vrijhoeven
Honored Contributor

Re: Will 'xargs' help on "parameter list too long"?

Hi,

I am afraid it would not work for the ls. It could work for input commands.

ls dir | grep 'o$'

There are limits you can reach and the are defined in /usr/include/limits.h

I would nod advice you to change those but they will give you some insight.

Gideon
Jean-Louis Phelix
Honored Contributor
Solution

Re: Will 'xargs' help on "parameter list too long"?

Hi,

Try :

find dir -name '*.o'

Regards.
It works for me (┬й Bill McNAMARA ...)
Rob_132
Regular Advisor

Re: Will 'xargs' help on "parameter list too long"?

Another case of taking something simple and turning it into a complex problem!

SEP - may have netted more points w/ attachmnet

SF - same error message

GV - OK, except omits dir name

JLP - Works! Thanks!

** Thread closed **

Thanks all!
A. Clay Stephenson
Acclaimed Contributor

Re: Will 'xargs' help on "parameter list too long"?

Xargs will not help in this case because the *.o is instantiated by the shell before xargs gets a chance to operate on it. We can leverage the find command and restrict this to a single directory using -path. This will work because -path './dir/*.o' is evaluated by find without the shell expanding it first BUT ONLY if quoted.

This will work for you:
find . -path './dir/*.o' -exec ls -l {} \;
or simply
find . -path './dir/*.o'
if all you want to do is list the .o files only in dir.

Now for a valid (and more efficient) use of xargs to replace the -exec clause in the command above:

find . -path './dir/*.o' | xargs ls -l


If it ain't broke, I can fix that.
Jean-Luc Oudart
Honored Contributor

Re: Will 'xargs' help on "parameter list too long"?

Furthermore...

find . -path './dir/*.o' | xargs ls -l10

This will reduce the number of processes (buffer=10)

Regards,
Jean-Luc
fiat lux
Rob_132
Regular Advisor

Re: Will 'xargs' help on "parameter list too long"?

...and 10 for Clay for the insightful explanation that accompanied his response.

Rob
Jean-Luc Oudart
Honored Contributor

Re: Will 'xargs' help on "parameter list too long"?

Sorry ..
please read xargs -l10
e.g.
xargs -l10 ll

regards,
Jean-Luc
fiat lux