"ls -al * " not work

Bill Davidsen davidsen at tmr.com
Fri Nov 23 20:21:55 UTC 2007


chloe K wrote:
> Hi
> 
> My ls command not works  properly
> Are there many files problem?
> 
> [host]# ls -al |wc -l
> 55264
> 
> [host]# ls -al *.db |more
> -bash: /bin/ls: Argument list too long
> 
> [host]# ls -al *
> -bash: /bin/ls: Argument list too long
> [host]# ls -al *.*
> -bash: /bin/ls: Argument list too long
> 
Note that this comes from bash, not ls, and it results from expansion of 
the list to more characters than will fit in the buffer used to pass 
data to the (ls) command.

The kernel max has been expanded recently, but the bash shell probably 
has some kind of limit. If you have a lot of name, really long names, 
you can hit this. There are many ways to get around the problem, the 
best is not to have everything in one directory ;-)

you can do workarounds with find, xargs, little shell loops, etc:
   ls -a | while read name; do ls -l "$name"; done
if you have to use this type of directory structure you may have to 
learn other workarounds.

-- 
Bill Davidsen <davidsen at tmr.com>
   "We have more to fear from the bungling of the incompetent than from
the machinations of the wicked."  - from Slashdot




More information about the fedora-list mailing list