3 ms·
Regular `ls` lists files in a variable number of columns depending on the terminal width. Many utils enable or disable color output depending on the destination
by aasasd 8y ago
Regular `ls` lists files in a variable number of columns depending on the terminal width. Many utils enable or disable color output depending on the destination of that output, and on terminal's capabilities.
CLI utils are full of special behaviors for convenience of use by people. To enable strict consistence that is mostly necessary for usage by other programs, there are flags.
- Cogito 8y agoMany CLI tools will detect if they are running in an interactive shell and change their output accordingly. Git for example will colourise terminal output if it can tell a person is interacting with it, but if a script is calling then the colour markers won't be added (and there are many many other examples of similar behaviour).
- laumars 8y agoThe moment you pipe ‘ls’ it will fallback to using just one column. In fact a great deal of CLI tools (and particularly coreutils like GNU) will have nice usability features this will auto-disable the moment the output file is not a TTY. For example, run the following commands and compare the output: ls ~ ls ~ | cat grep --color=auto ${hostname} /etc/hosts grep --color=auto ${hostname} /etc/hosts | cat You might be surprised at just how different and predictable the terminal utilities behave when they detect they’re being piped.