I have a number of files with very long names. Please, is there a way to use ls -C and truncate the file names to get more columns for an overall view?
Or is there a better way to get a compact listing?
I have a number of files with very long names. Please, is there a way to use ls -C and truncate the file names to get more columns for an overall view?
Or is there a better way to get a compact 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 *

Assuming an 80 column screen, I like to use
ls -F | perl -lne 's/(.{34}).*/$1... /s ; print' | column -x | more
use ls -FC instead to sort by recency
(Sidenote: my ls already scrolls because it's aliased to ls -CF --color | more -r. Not sure that's best practice...)