If you want GNU ls features on FreeBSd, you can install the gnuls package and alias ls
to gnuls
.
If you want to stick to the base software, you can post-process the output of ls
. (Script reposted from how do you sort du output by size?) This works on any POSIX system.
CLICOLOR_FORCE=1 ls | awk '
function human(x) {
s="kMGTEPYZ";
while (x>=1000 && length(s)>1)
{x/=1024; s=substr(s,2)}
return int(x+0.5) substr(s,1,1)
}
{gsub(/^[0-9]+/, human($1)); print}'
CLICOLOR_FORCE
causes BSD ls
to use colors even if it isn't writing to a terminal. On the other hand, because ls
isn't writing to a terminal, you'll get one file per line instead of columns. On FreeBSD, you can use the option -C
to get columns, but then the postprocessing script becomes a lot more complex since it needs to find sizes in the middle of the line. Try this (untested):
CLICOLOR_FORCE=1 ls -C | awk '
function human(x) {
s="kMGTEPYZ";
while (x>=1000 && length(s)>1)
{x/=1024; s=substr(s,2)}
return int(x+0.5) substr(s,1,1)
}
{gsub(/(^| )[0-9]+/, human($1)); print}'
alias ls="ls -h"
– Kusalananda Aug 10 '16 at 11:34ls
does not output "human readable" sizes without-h
. – Kusalananda Aug 10 '16 at 11:36ls -sh
. The manual saysh, --human-readable: with -l and/or -s, print human readable sizes (e.g., 1K 234M 2G)
– ilkkachu Aug 10 '16 at 11:40ls
on my OS X doesn't support that combination. Don't know about FreeBSD. (Obvious workaround: install GNU ls) – ilkkachu Aug 10 '16 at 11:41-h When used with the -l option, use unit suffixes
. It does not work out of the box in FreeBSD. – viuser Aug 10 '16 at 11:43csh
and inbash
). If you say what version of FreeBSD and which login shell you are using, we will help. – Aug 10 '16 at 12:11echo $TERM
please. – Aug 10 '16 at 12:17ls -h
doesn't display any size whatsoever. Onlyls -s
andls -l
display sizes. – Gilles 'SO- stop being evil' Aug 10 '16 at 23:06