I am writing a simple helper function to show a specific folder in the format I want:
find . -maxdepth 1 -not -name "." -printf '[%TY-%Tm-%Td]\t%s\t%f\n' | sort -n
However I want to show the filesizes in a nicer format. I found this answer which I used to create a bash function called hr
.
user@host:~$ hr 12345
12M
I tried using this in the find
call as so:
find . -maxdepth 1 -not -name "." -printf '[%TY-%Tm-%Td]\t'$(hr %s)'\t%f\n' | sort -n
But it still continues to show the full filesize. How should I modify this so it works as expected?
Best Answer
Assuming sane file names, with
numfmt
fromgnu coreutils
(8.21
or later):You can further format the output via
--padding=
and--format=
options (and with most recent versions even set output precision) e.g:or
If you don't mind the permissions & links-count columns, with
gnu
ls
: