bug#49994: upgrade: have "-s" of 'ls' display alloc'd sizes for specified "--block-size"
On 2021/08/20 11:31, Paul Eggert wrote: On 8/20/21 10:40 AM, L A Walsh wrote: I wanted it just to work So use 'stat -c "%s %n"'. That works just fine. 'stat' is a good tool for this job, and there's no need for yet another 'ls' option for this rare use case. stat doesn't come close. I wanted the automatic-multi column output of 'ls' like "ls -s" gives, but instead of the disk-space-allocated number as 'du' would be sufficient for, I wanted 'byte' output -- like the default output of 'ls' gives. By default, ls gives you names, or with -l gives you bytes. If you want a short form that gives you bytes+name, the obvious attempt would be use of -s with a flag that would say to display bytes. This rare use case? Having a file-list command that displays filename+size in a compact form seems one of the top use use-cases. Yet that seems to be missing. The default of ls -s should be to display size, not allocated blocks, since if you want that, 'du' is what first comes to mind to find the diskspace-used.
bug#49994: upgrade: have "-s" of 'ls' display alloc'd sizes for specified "--block-size"
On 8/20/21 10:40 AM, L A Walsh wrote: I wanted it just to work So use 'stat -c "%s %n"'. That works just fine. 'stat' is a good tool for this job, and there's no need for yet another 'ls' option for this rare use case.
bug#49994: upgrade: have "-s" of 'ls' display alloc'd sizes for specified "--block-size"
On 2021/08/20 08:08, Paul Eggert wrote: On 8/20/21 12:02 AM, L A Walsh wrote: When I use "-b" in du (equivalent to '--apparent-size --block-size=1) Previously in this thread you asked for "allocated space for a file on a device", which is why I was talking about that number. --- No, I wanted space that "would" be allocated on a device if the device allocated size in bytes -- which is what 'du' does. I even said I wanted the output of ls's block-size output to be enhanced to pay attention to what users specify via that parameter. I wanted a simple multi-column output like 'ls' provides. I wanted it just to work -- not require a program or figuring it out but just have it be user-friendly -- something the tools designed by gnu definitely are not.
bug#49994: upgrade: have "-s" of 'ls' display alloc'd sizes for specified "--block-size"
On 8/20/21 12:02 AM, L A Walsh wrote: When I use "-b" in du (equivalent to '--apparent-size --block-size=1) Previously in this thread you asked for "allocated space for a file on a device", which is why I was talking about that number. Now you're asking for apparent size, which is a different number. If you want apparent size, you can use 'ls -l', or follow Andreas's suggestion and use something like 'stat -c "%s %n"'. However, apparent size might be quite different from allocated space, as can be seen in the 1st and 6th columns of the last two lines of the following: $ echo '' >a $ truncate -s 1TB b; echo '' >>b $ ls -ls --block-size=1 a b 4096 -rw-rw-r-- 1 eggert eggert 1 Aug 20 08:07 a 4096 -rw-rw-r-- 1 eggert eggert 10001 Aug 20 08:07 b
bug#49994: upgrade: have "-s" of 'ls' display alloc'd sizes for specified "--block-size"
There is stat and numfmt. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
bug#49994: upgrade: have "-s" of 'ls' display alloc'd sizes for specified "--block-size"
On 2021/08/18 08:39, Paul Eggert wrote: Perhaps your request would be more clear if you gave a specific example of what you want and why --block-size doesn't do what you want. I wanted to use ls to list the size of files in bytes, and use Binary prefixes K=1024, M=1024**2, G=1024**3 to display the the numeric portion with a maximum 3 digits or use a floating point format with up to 1 digit to the right of the decimal point: similar and as rounded by use of "%.1f" as in printf. Using a list of 577 files in file "files.txt", the existing 'ls' using: cat files.txt|xargs /usr/bin/ls --block-size=1 -1dhsS Instead of displaying the file sizes in bytes, it showed them rounded to the nearest 4K, so sorting by size and displaying only the 1st of a given size, I only ended up with 13 unique file-sizes in the list: 312K lib/perl5db.pl 200K lib/Unicode/Collate/Locale/ja.pl 100K lib/Unicode/Collate/Locale/zh_pin.pl 96K ext/XS-APItest/t/utf8_warn_base.pl 36K regen/opcode.pl 32K ext/DynaLoader/DynaLoader_pm.PL 28K regen/feature.pl 24K ext/XS-APItest/t/handy_base.pl 20K Porting/checkURL.pl 16K Porting/corelist.pl 12K t/lib/dbmt_common.pl 8.0K dist/lib/lib_pm.PL 4.0K cpan/Pod-Simple/t/ascii_order.pl I expected closer to 100 or more files displayed with size under 1000 bytes. If 'ls' used the user-specified 'block-size' of 1 byte, the number of files displayed is actually 279, or over 20 times the number of files with some names elided for sake of brevity. 310K lib/perl5db.pl 197K cpan/Unicode-Collate/Collate/Locale/ja.pl 138K regen/mk_invlists.pl 126K Porting/bisect-runner.pl ... 53.3K win32/bin/search.pl 52.1K cpan/IO-Compress/t/compress/generic.pl 49.9K t/test.pl 46.4K utils/perlbug.PL ... 17.4K Porting/pod_lib.pl 17.1K Porting/add-package.pl 6.7K dist/Devel-PPPort/Makefile.PL 6.6K cpan/Sys-Syslog/Makefile.PL 6.5K cpan/podlators/Makefile.PL 5.5K cpan/Unicode-Collate/Collate/Locale/da.pl 5.4K symbian/makesis.pl ... 1.2K ext/Hash-Util/Makefile.PL 1.1K win32/bin/perlglob.pl 1.0K ext/File-Glob/Makefile.PL 997 cpan/Unicode-Collate/Makefile.PL 983 cpan/Unicode-Collate/Collate/Locale/mk.pl ... 125 dist/Time-HiRes/hints/sco.pl 110 ext/VMS-DCLsym/Makefile.PL 104 dist/Time-HiRes/hints/dynixptx.pl 101 cpan/DB_File/hints/dynixptx.pl 97 ext/POSIX/hints/mint.pl 94 dist/IO/hints/sco.pl 11 symbian/uid.pl 6 t/op/svleak.pl 3 t/run/dtrace.pl 2 cpan/Module-Load-Conditional/t/to_load/LoadMe.pl - Instead 'ls' displays 4.0K for a file that is only 2 bytes. Clearly it isn't using the block-size specified by the user in the same way 'du' does: cd /tmp echo "1" >out.pl du -b out.pl 2 out.pl Ishtar:/tmp> /bin/ls --block-size=1 -1dhsS /tmp/out.pl 4.0K /tmp/out.pl --- When I use "-b" in du (equivalent to '--apparent-size --block-size=1), I get a size of '2' which one would expect for a file with 2 chars in it. however, ls displays 4.0K. Clearly it isn't using the --block-size=1 that 'du' is using.