Can I truncate long file names in ls listing
You could do something like:
ls | cut -c1-20 | columns -W "${COLUMNS:-80}"
(that's columns
with an s
from GNU autogen). Or:
ls | cut -c1-20 | column -c"${COLUMNS:-80}"
Using column
as found on BSDs or in bsdmainutils
on Debian or its derivatives.
zsh
also has support to print things in columns, so you could define a function like:
setopt extendedglob
c() print -rC$[COLUMNS/(($1)+2)] -- "${(M)@[2,-1]##?(#c0,$[$1])}"
And use it as:
c 20 *.txt
To print the list txt files in columns, truncated to 20 characters.
And to make it a bit crazier, you could add:
command_not_found_handler() {(($1)) && c "$@"}
That way, you can also do:
20 *
Or even:
8+8 *