Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I would like to list all files in the order of big to small in size and the files could be present anywhere in a certain folder.

share|improve this question

7 Answers 7

Simply use something like:

ls -lS /path/to/folder/

Capital S.

This will sort files in size.

Also see:

man ls

-S     sort by file size


To exclude directories:

ls -lS | grep -v '^d' 

Update 2:

I see now how it still shows symbolic links, which could be folders. Symbolic links always start with a letter l, as in link.

Change the command to filter for a -. This should only leave regular files:

ls -lS | grep '^-'

On my system this only shows regular files.

update 3:

To add recursion I would leave the sorting of the lines to the sort command and tell it to use the 5th column to sort on.

ls -lR | grep '^-' | sort -k 5 -rn

-rn means Reverse and numeric to get the biggest files at the top. Down side of this command is that it does not show the full path of the files.

If you do need the full path of the files, use something like this:

find . -type f  | xargs du -h | sort -rn

The find command will recursively list all files in all sub directories of ., xargs will use the output of find as an argument to du -h meaning disk usage -humanreadable and then sort the output again.

share|improve this answer
I don't want it to list directories, just want to see the files in a certain order. –  Joe Nov 3 '12 at 15:30
Updated my awnser. –  delh Nov 3 '12 at 15:34
It still shows unwanted folders and totals, I just need list of files. –  Joe Nov 3 '12 at 15:38
Updated my awnser. Do you want to see full lines or only file size / file name? –  delh Nov 3 '12 at 15:46
du gives the disk usage which is different from the file size. With (GNU) du -h, numerical sort won't work (you'll need the -h GNU option to sort). xargs expect a list of possibly quoted words as input so it won't work if filenames contain blanks or quoted characters. –  Stéphane Chazelas Nov 3 '12 at 23:57

You could use something like find and sort.

find . -type f -ls | sort -r -n -k7

(the -ls option is not standard but is found in many find implementations, not only the GNU one. In GNU find and others, it displays something similar to ls -li with a few exceptions, for instance, files with ACLs are not marked with a +)

If the file names may contain newline characters, with GNU find and GNU sort:

find . -type f -ls -printf '\0' | sort -zk7rn | tr -d '\0'
share|improve this answer
This assumes "group" column (from -ls) not containing any spaces (hence -k 7 parameter), but it isn't necessarily the case. –  kolistivra Nov 3 '14 at 16:00

With zsh and GNU ls:

ls -ldU -- **/*(.OL)

(note that older versions of zsh had issues with file sizes over 2^32).

Some operating systems have a limit on the size of the argument list passed to a command. In those cases, you'd need:

autoload -U zargs
zargs ./**/*(.OL) -- ls -ldU

If you just want the list of files and not the detailed output, just do:

print -rl -- **/*(.OL)

If you want to include hidden files (whose name starts with a dot, except . and ..), add the D globbing qualifier:

print -rl -- **/*(.DOL)
share|improve this answer

Saying that "the files could be present anywhere in a certain folder" implies that you want to recursively descend all directories (folders) within the starting directory (folder). This is what find is meant to do:

find . -type f -exec ls -lSd {} +

This "finds" all files in the current working directory (.). For each file found, an ls process is run to sort the objects found in size order. The + terminator to the -exec causes multiple arguments to be passed as a list to ls. Unless your directory (folder) contains a very large number of files, you should have one list (and thus one process forked), leading to the result you desire.

share|improve this answer
this is nice as it allows you to use the -h modifier on ls to show nice file sizes –  shmish111 May 16 at 8:48

I wrote something to this extent a while back. You could pass an argument to specify how many files to list, or just type big, in what case you get 10.

big () { 
    if [ $1 ]; then
    du | sort -nr | head -n $NUM_FILES
share|improve this answer

Try these, it works fine for me.

$ find /home/san -type f -printf '%s %p\n'| sort -nr | head -n 10

# find /root -type f -exec ls -lS {} + | head -n 10 | awk '{ print $5, $9 }'

Not perfect answer though but works to some extent

$ ls -lS |grep  '^-' | head -n 6 
share|improve this answer

Adding to delh's answer and Stéphane Chazelas' comment...

find -print0 combined with xargs -0 adds support for blanks / spaces / whatnots.

du -h | sort -rn doesn't sort properly between different byte multiples, e.g. 1.1M will show after 128K, which is wrong.

sort -rh (--human-numeric-sort) takes care of that, but it only works on GNU's version.

The commands below will provide the desired output.

Human-readable, on GNU's sort / Linux:

find . -type f -print0 | xargs -0 du -h | sort -rh

In kilobyte units, on BSD / OSX / others:

find . -type f -print0 | xargs -0 du -k | sort -rn

For BSD / OSX, also see

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.