How to sort by file size with ls?

Linux & Unix newsgroup archiveUnix shell2005

Linuxmisc » Unix shell

Wonde #1 / 6 Sun, 02 Oct 2005 11:00:36 GMT
Hi,

Could anyone kindly tell me how to let "ls -l" output the file details
sorted by file size? Or any shell tools or scripts are also welcome.

Thanks.

Wonder

Chris F.A. Johnso #2 / 6 Sun, 02 Oct 2005 13:13:56 GMT

If you have the GNU vesion of ls, use the -S option.
    Otherwise, pipe it through sort:

ls -l | sort -n +4

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2003, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

Ed Schaefe #3 / 6 Sun, 02 Oct 2005 13:21:40 GMT
Sort by the 5th field, numeric, descending:

ls -l |sort -k5rn,5

Regards,

Ed

Arvid O #4 / 6 Sun, 02 Oct 2005 16:16:44 GMT

ls -l | sort -r -n -k 5

Arvid

Stephane CHAZELA #5 / 6 Sun, 02 Oct 2005 18:41:36 GMT

With zsh:

ls -fld *(OL)

--
Stphane

rakesh shar #6 / 6 Mon, 03 Oct 2005 03:07:21 GMT

ls -l | sort -k 5n

or better still, if u have gnu ls:

ls -Slr

will list files in increasing order of size.

This page is kept from the Linuxmisc archive of Linux and Unix newsgroups (snapshot 2013). Posts are shown as they were published, so commands, versions and addresses date from the original discussion. Linuxmisc.com now publishes a guide to online casinos in Canada.