[wellylug] ls capacity

Grant McLean grantm at web.co.nz
Fri Nov 29 15:42:42 NZDT 2002


Edouard CHALARON wrote:
> What is the maximum amount of files you can list in a 
> directory ?
> like : ls *.jpg

That touches on a number of different areas.

As far as I'm aware, there is no limit on the number of
files you can have in a directory (beyond the physical 
capacity of the filesystem and perhaps a 2GB limit on the
size of the '.' special file).  However the more files that
a directory contains, the slower it will be to open any
given one of them.

If you have thousands of files in a directory and you run 
the 'ls' command then you should (eventually) get a list
of all the files.

However, if you run 'ls *.jpg' your command shell does not
pass the pattern to ls (as the DOS command shell does).
Instead, the shell expands the pattern into a list of 
filenames and passes 'ls' all the names.

It is possible that if you had a lot of files in a 
directory, that you might exceed the maximum allowable
command line length.  Although I've managed to exceed
the DOS (or Windows) command length limitations, I haven't
managed to break a Linux shell in the same way.  I couldn't
find any reference to a maximum command length limitation
of the 'bash' shell so I kicked of a little test a few
minutes ago.  It's up to 35000 characters and still going.

Another feature of the shell pattern expansion (called
'globbing') is that it sorts the matching filenames into 
alphabetical order before passing them to the called
program.  So I guess with lots of files you could run up
against memory limitations.

Here's an alternative to your ls command that should work 
for any number of files:

  ls -f | grep '\.jpg$'

The '-f' tells 'ls' not to try and sort the files either.

If you do need to have lots of individual files, it's 
probably a good idea to split them among subdirectories.
A common technique is to use the first one or two 
characters of the filename eg:

  elephant.jpg    would become e/el/elephant.jpg
  cheese.jpg      would become c/ch/cheese.jpg

etc.

Are you having a specific problem with a large number
of files?  

Regards
Grant

===============================================================
Grant McLean        BearingPoint Inc - formerly The Web Limited
+64 4 495 9026           Level 6, 20 Customhouse Quay, Box 1195
gmclean at bearingpoint.biz                Wellington, New Zealand





------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/CBxunD/vN2EAA/xGHJAA/0XFolB/TM
---------------------------------------------------------------------~->

  .-.   Wellington
  /V\   Linux
 // \\  Users       
/(   )\ Group
 ^^-^^
        http://wlug.paradise.net.nz/

To unsubscribe from this group, send an email to:
wellylug-unsubscribe at egroups.com
  

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 





More information about the wellylug mailing list