How to format the output of ls? How to format the output of ls? linux linux

How to format the output of ls?


You can use printf and shell globbing rather than attempt to format ls output.

Try something like:

$ printf '    %s \\\n' *.h    a.h \    b.h \    c.h \

ls is really meant as an "interactive" tool for humans, avoid using it for anything else.


ls -1 *.h | sed 's/^/    /' | sed 's/$/ \\/'

Alternatively, you could say:

ls -1 *.h | sed 's/.*/    & \\/'


see

find . -maxdepth 3 -type f -iname "*" -printf "%h,%f,%CY-%Cm-%Cd %CT,%s,%u,%M\n"