As I understand, the
ls command calls
getdents, which returns up to x number of directory entries. Are there any other system calls involved? If I run
ls -l, are there any more system calls? I am trying to determine if
ls -l is more expensive and hence slower than
/bin/ls usually sorts the output. I'm not sure if your "efficient" question is just over system calls or the entire work that is done, but
/bin/ls -f would probably do the least work. It only returns the filenames in directory order. No sorting, no additional inode lookups to get metadata (as
ls -l would do).
Also, if your default
ls is colorizing, it may be doing the equivalent of
ls -l anyway so that it can tell how to color the output.
ls -l is definitely more expensive, since it has to query the file system for metadata such as owner, group, permissions, access time, etc. Vanilla
/bin/ls only has to look up the names of the entries in the directory being listed.
ls may be aliased on your system to something less vanilla than
type ls to see if that's the case.