Print n lines of command --help to stdout

It's like a curiosity that I couldn't solve it (try sed, awk, tail, head, etc.).

It works:

$ ls --help | head -n 2
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).

      

Why doesn't it work with other teams?

$ tree --help | head -n 2 
Prints the whole --help! not just the first 2 lines!

      

+3


source to share


1 answer


tree

(and some other commands) print their help to stderr, not stdout. You can simply redirect both with |&

instead |

:



tree --help |& head -n2

      

+6


source







All Articles