Take the 2-minute tour ×
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
add comment

5 Answers

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, 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
I need to do it recursively also so I did ls -lSR, but its still not ordered. –  Joe Nov 3 '12 at 15:51
show 6 more comments

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
add comment

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
add comment

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
add comment

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
add comment

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.