Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] how to tune reiser4 for millions of files?



Quoting Stephen J. Turnbull:
> One thing: ls is possibly the slowest possible application imaginable,
> because all it does is make syscalls.  I would expect that the problem
> is not the syscall overhead (although I bet that's non-negligible),

I would tend to guess that his ls is trying to SORT the entire file listing
before printing anything, which of course cannot be done before having
loaded the ENTIRE file list in memory.

Michal, when one needs to get the list of files from a big directory using
the shell, using "find" is always the fastest way to go: a plain "find"
will only call opendir, readdir and closedir, not bothering to stat the
files or anything -- and will neither try to sort the output.

Knowing how to pipe the result of find into xargs to get your files
processed one by one is a very useful thing to learn for all shell users.
One example:

	find . -print0 | xargs -0 -r -- ls -l

... will give you a detailed unsorted recursive file listing from the
current directory. Note that xargs assumes by default that it can provide
several filenames at once to the program it is calling; use the -L option
to specify a limit, e.g. -L 1 if your program can only deal with one
filename at once:

find . -maxdepth 1 -type f -print0 | xargs -0 -L 1 -r -- ~/myprogram

-print0 is important to deal with filenames that include special
characters. -maxdepth 1 here means to not recurse into subdirectories.
-type f means "only regular files", e.g. don't try to run my program on
directories.

See the manpages for all the amazing details.

-- 
()  Patrick (L.) Bernier <pat@example.com>
()  http://www.TZoNE.ORG/~pat/
()  GPG B070 BBB6 188D EB1E 353A 90E4 96FF D8EB 1ADC BE03
()  "Words have meaning, and names have power." -- Lorien


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links