SUMMARY: One question (sorting filesize.)

From: Ye Tun (ye@maia.cl.au.ac.th)
Date: Thu Feb 15 1996 - 21:29:06 CST


Dear Sun-manager....

Thanks for all those who response...(name below). Those help me alot!

misik@alpha.dcs.fmph.uniba.sk (Andrej Misik)
lkopl@ctp.com (Leslie Koplow)
"Mike Varney - SysAdmin, HRI" <mlv03@health.state.ny.us>
Margaret Shinkle <marge@hri.com>
Milt Webb <milt@iqsc.com>
albert@esther.rad.tju.edu (Dr. Micheal Albert)
brano@kar.elf.stuba.sk (Branislav Bozgai)
antonio.colombo@scomta.jrc.it
Todd Michael Kennedy <tkennedy@phoenix.csc.calpoly.edu>
anderson@neon.mitre.org (Mark S. Anderson)
Mitch Patenaude <mrp@hilbert>
Stephen Potter <spp@psisa.com>
"MR.OMAR" <rosley@tsi.com.my>
nleroy@norland.idcnet.com (Nicholas R LeRoy)

===== My Original question is. ======

>
> Dear Sun manager subscriber!
>
> How can you list the file with it's size. i mean not with block size!
> I know how to "ls -ls |sort -n" but that really doesn't solve my problem
> because block size can be the same but the real file size can be different.
>
> I want to sort the actual file size! is there any script or utility
> program to perform this.

===== ************************ =====

From: misik@alpha.dcs.fmph.uniba.sk (Andrej Misik)

ls -al | sed -e 's/ */ /g' | cut -d' ' -f 5,9 | sort -nbt' ' -2 | cut -d' ' -f2

        hope this helps.

=========================

From: lkopl@ctp.com (Leslie Koplow)

du -s filename | sort

=========================

From: "Mike Varney - SysAdmin, HRI" <mlv03@health.state.ny.us>

When you "ls -l", the 5th column is the file size in bytes. It's the
number just before the date. Sort by that field.

=========================

From: Margaret Shinkle <marge@hri.com>

/bin/du -s filename will give the exact size

======================

From: Milt Webb <milt@iqsc.com>

Try ls -l and sort on field 5 ...

=====================

From: albert@esther.rad.tju.edu (Dr. Micheal Albert)

Dear Friend:

 I am not sure what you are asking. Do you know about the
"du" command?

  Best wishes,
     Mike

====================

From: brano@kar.elf.stuba.sk (Branislav Bozgai)

Have a look at du(1M) e.g. 'du -ka'

=========================

From: antonio.colombo@scomta.jrc.it

Ye,

ls -l|nawk ' { printf("%12.1d %s\n",$5,$9) } '|sort -n
              | open curly braces | close curly braces
                                 | backslash

If you have a compiler, you can change a bit the following program:

howlong.c:

#include <stdio.h>
#include <sys/types.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <errno.h>
main(a
/*
 * Usage: howlong name_of_a_file
 *
 * in stdout a string with the required length
 *
 * in stderr some diagnostics, that could be ignored
 *
 * exit(0) == everything OK
 * exit(1) == error in stdin, (some input missing).
 * exit(2) == error in stat, processing path name.
 */
{
struct stat filedata;
int istatus;

if (argc != 2) {
        printf("Usage: howlong name_of_a_file\n");
        exit(1);
}
istatus=stat(argv[1],&filedata); /**/
if (istatus == -1)
        {
        fprintf(stderr,"error processing: %s\n",argv[1]);
        fprintf(stderr,"istatus=%d, errno=%d:\n",istatus,errno);
        exit(2);
}
fprintf(stdout,"%d\n",filedata.st_size);
exit(0);
}
========================

From: Todd Michael Kennedy <tkennedy@phoenix.csc.calpoly.edu>

You were close with your original sort command. Just need to add a few more
options:

  ls -ls | sort +5n -6

That will sort your 'ls' output in order of increasing file size.

Best Regards,
  Todd
=======================

From: anderson@neon.mitre.org (Mark S. Anderson)

SunOS 4.1.x:

        ls -l | grep -v '^d' | sort -n +3

SunOS 5.x

        ls -lg | grep -v '^d' | sort -n +3

(The grep filters out directory names.)

======================

From: Mitch Patenaude <mrp@hilbert>

Read the man page for 'sort(1)'

hilbert> ls -l | sort -n +3
total 1041
-rw-r--r-- 1 mrp 75 Oct 13 16:53 strip.sed
-rw-r--r-- 1 mrp 1016 Oct 13 16:53 config.h
-rw-r--r-- 1 mrp 1383 Oct 13 16:53 markov.h
-rw-r--r-- 1 mrp 1441 Oct 13 16:53 Makefile
-rw-r--r-- 1 mrp 4423 Oct 13 17:12 fubar.mkv.gz
-rw-r--r-- 1 mrp 5000 Oct 13 16:53 db_tree.c
-rw-r--r-- 1 mrp 5892 Oct 13 16:53 spew.c
-rw-r--r-- 1 mrp 6347 Oct 13 16:53 common.c
-rw-r--r-- 1 mrp 6896 Oct 13 16:53 build_db.c
-rw-r--r-- 1 mrp 7113 Aug 28 1994 markov.shar.gz
-rw-r--r-- 1 mrp 71011 Oct 13 16:53 intertext.mkv.gz
-rw------- 1 mrp 149240 Oct 13 16:53 alt.personals.mkv.gz
-rw-r--r-- 1 mrp 228391 Oct 13 16:53 gospels.mkv.gz
-rw-r--r-- 1 mrp 535921 Aug 28 1994 good_dbs.shar.gz
hilbert> ls -l | sort -rn +3
-rw-r--r-- 1 mrp 535921 Aug 28 1994 good_dbs.shar.gz
-rw-r--r-- 1 mrp 228391 Oct 13 16:53 gospels.mkv.gz
-rw------- 1 mrp 149240 Oct 13 16:53 alt.personals.mkv.gz
-rw-r--r-- 1 mrp 71011 Oct 13 16:53 intertext.mkv.gz
-rw-r--r-- 1 mrp 7113 Aug 28 1994 markov.shar.gz
-rw-r--r-- 1 mrp 6896 Oct 13 16:53 build_db.c
-rw-r--r-- 1 mrp 6347 Oct 13 16:53 common.c
-rw-r--r-- 1 mrp 5892 Oct 13 16:53 spew.c
-rw-r--r-- 1 mrp 5000 Oct 13 16:53 db_tree.c
-rw-r--r-- 1 mrp 4423 Oct 13 17:12 fubar.mkv.gz
-rw-r--r-- 1 mrp 1441 Oct 13 16:53 Makefile
-rw-r--r-- 1 mrp 1383 Oct 13 16:53 markov.h
-rw-r--r-- 1 mrp 1016 Oct 13 16:53 config.h
-rw-r--r-- 1 mrp 75 Oct 13 16:53 strip.sed
total 1041

  -- Mitch Patenaude
     mrp@mux.com
========================

From: Stephen Potter <spp@psisa.com>

There are a number of ways to do this. One would be to do an ls -l and use
awk to pull out the fields you want (size and filename):

ls -l | awk '{print $5, $NF}' | sort -n

You could also write a perl script to do it. This task is left as an
exercise to the reader. ;-)

========================

From: "MR.OMAR" <rosley@tsi.com.my>

Ye,

   try this small script:

   ls -al | awk '{printf("%10d %s\n",$5,$9) }' | sort -n

   you can make it as a script file, give it an eXecute permission and
   run it....you can change it any-way you want it...
   hope it's useful....

======================

From: nleroy@norland.idcnet.com (Nicholas R LeRoy)

I wrote a little script I call 'lss' - it also prints the size out in 1k
blocks, too. here it is:

#!/bin/sh
ls -l $* | sort -n +4 | awk '{ printf ("%5d %s\n", ($5 / 1024 + 0.999), $0) }'

BTW: It is setup to work with Linux's ls, which I believe has the columns
different by a little bit, so you may need to tweek the +4 to +5 or
somesuch.

===============

REgards,

*[ Ye ]*
                     \```\
   || ) O O ) || ,Oo=-=oOo=-=oOo=-=oOo=-,
+--++------------.oOOo--U--ooOo.------------++--+ ( Becareful with what )
 \ Ye Tun ye@maia.au.ac.th \ \ you wish for, you /
  \ Computer Laboratory +66 2 3004543 ext. 3672 \ | might get it /
   \ Assumption University \ \_______, ___/
    \ Bangkok 10240, Thailand \ .__o '
     +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-Oooo.-=-=-=-=-=-=-=-=#--_-\_<,
                            .oooO ( ) (*)/`(*)
                            ( ) ) /
                             \ ( (_/
                              \_)



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:10:53 CDT