Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

14
  • 5
    What is this "full string lookup" you keep referencing? Commented Nov 19, 2022 at 22:27
  • 16
    If you really are using ls in a script, that’s a sign you’re doing something wrong, and you’d probably benefit more by avoiding the ls invocation altogether than by optimising it. Commented Nov 19, 2022 at 23:14
  • 26
    The name lookups the kernel needs to make are likely not all that significant compared to all the other bookkeeping involved in starting a new process and executing a new program in it. If it's ls and grep you're thinking, you might get better results by switching to a programming language with better tooling for data processing Commented Nov 20, 2022 at 9:53
  • 8
    why not use ls to do operation on files in scripts, Why not parse ls (and what to do instead)? Commented Nov 20, 2022 at 11:48
  • 17
    There seems to be an implicit assumption here that the shell is doing a new PATH lookup on each execution of a binary. That's not true; there's a cache in bash preventing new PATH lookups in userspace, and the kernel has its own aggressive caching on its side of the userspace/kernel divide. The fork()+execve() part of running a new executable is much, much slower. Commented Nov 20, 2022 at 17:53