Timeline for Which is more efficient : ls -l *ABC* vs ls -l | grep ABC
Current License: CC BY-SA 3.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 3, 2017 at 7:14 | vote | accept | Cross2004 | ||
Nov 2, 2017 at 16:30 | comment | added | Basile Starynkevitch |
In almost all cases you should not care. Both are fast enough. Of course ls -l *ABC* is faster and better. BTW, you forgot to take into account the shell (doing the globbing). Does it count in your "efficiency" concern? The only practically meaningful case would be a huge directory (of million entries) which is uncommon ....
|
|
Nov 2, 2017 at 16:19 | answer | added | Keith Thompson | timeline score: 4 | |
Nov 2, 2017 at 15:43 | comment | added | Charles Duffy |
@123, sure, but it's useful to distinguish whether that's the situation here. And frankly, if someone "just want[s] to list files", it's surprising that performance matters (unless it's a really huge directory, in which case the biggest gains available come by way of telling ls not to sort).
|
|
Nov 2, 2017 at 15:42 | comment | added | 123 | @CharlesDuffy sometimes people just want to list files... | |
Nov 2, 2017 at 15:35 | comment | added | Charles Duffy |
What's the use case? If you want to pass a list of files to a different program, or iterate over them in your shell script, you shouldn't use ls at all -- not just for performance reasons, but for correctness reasons as well. See Why you shouldn't parse the output of ls
|
|
Nov 2, 2017 at 15:29 | answer | added | segfault | timeline score: 1 | |
Nov 2, 2017 at 15:25 | comment | added | 123 | In almost all cases a single process will be far more efficient than piping. | |
Nov 2, 2017 at 15:23 | comment | added | anubhava |
Of course ls -l *ABC*
|
|
Nov 2, 2017 at 15:23 | history | asked | Cross2004 | CC BY-SA 3.0 |