SUMMARY [Fwd: behavior of ls]

From: Jose Montilla (josem@corp.adaptec.com)
Date: Tue Oct 06 1998 - 16:17:23 CDT


Outstanding responses....here they are...

Subject:
        UBE/medium: Re: behavior of ls
    Date:
        Tue, 6 Oct 1998 14:12:31 -0700
    From:
        u-kevin@megami.veritas.com (Kevin Sheehan - Uniq)
 Reply-To:
        u-kevin@veritas.com
don't use csh - it obviously has a smaller limit on the size of the
argument list it is willing to expand.

Also, for large directories you might want to look at xargs...
__
Subject:
       Re: behavior of ls
   Date:
       Tue, 6 Oct 1998 12:55:03 -0700 (PDT)
   From:
       Michael Hocke <michaelh@slmd.com>

  look into the man page of csh(1). At the end of the text you will find
a
paragraph headed with 'NOTES' which explains that 'the maximum number of

arguments to a command for which filename expansion applies is
1706.'

Hope it helps.

______
- Michael

Subject:
           Re: behavior of ls
       Date:
           Tue, 06 Oct 1998 13:36:18 -0600
       From:
           Hardwired <leet@navidec.com>

For a good 'ls' command article, look here.

http://www.sunworld.com/swol-09-1998/swol-09-unix101.html


attached mail follows:


On Tue, 6 Oct 1998, Jose Montilla wrote:

> I have about 2000 plus files in a directory which gives me this output
> I have csh as my shell
> ls *
> Arguments too long
>
> change the shell to sh
> ls *
> file1
> file2
> file3
> ........
> file2000
> and it lists the files
>
> in csh rm, echo, file, and maybe some more comes out with the same
> output (error).
> Any thoughts ?

I believe that before executing ls (rm/mv/etc) both csh and sh take
the command line, and processes it to turn all wild cards into actual
file and path names. The result is that your short command "ls *"
actually is converted into the line "ls file1 file2 file3 ...
file2000" etc before it ls executes. In other words, the ls
command isn't given a single parameter which is "*", rather it is
given a list of 2000 parameters, which is a list of all the filenames.
The problem arises when the list of files exceed the maximum line
length allowed by csh (I thinks it's up around 64k characters, but I
could be wrong about that).

You can verify this by trying the command:

  ls '*'

the single quotes tell the shell not to convert the "*" into a list of
files. If you don't have a file with the name "*" then you should see
an error message that looks something like "*: No such file or
directory".

The solution is easy. Don't generate a list longer than the maximum
allowed line length;-) To do that, you generally use the xargs
program. In this case you would want something like:

  ls | xargs -n 10 ls -alFd

what xargs(1) does (in this example) is collect 10 arguments (in this
case they are file names, since ls is feeding file names into the
pipe), then runs the command "ls -alFd <arg1> <arg2> ... <arg10>" for
each group of 10 arguments as read from the pipe.

Hope you find this useful,

Rgds,

-H-

Harvey M Wamboldt ^ E-Mail: harvey@iotek.ns.ca
MDA Inc 1000 Windmill Rd. Suite 60 ^ Fax: (902)468-2278
Dartmouth NS, B3B 1L7, Canada ^ Phone: (902)481-3531



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:12:50 CDT