Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

10 Answers 10

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 '15 at 8:48

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
awk works fine if filenames don't contain any spaces. – Eir Nym Mar 20 at 8:01
yes .. use 'sed' and replace space with underscore? if that helps – an1512 Apr 12 at 9:29
No, I use sed to cut output – Eir Nym Apr 12 at 11:21

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

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 http://unix.stackexchange.com/a/188375/82895.

share|improve this answer

File list display in reverse order: ls -lSrh

For ascending order: ls -lSh

share|improve this answer
+1 for using the -h flag for human-friendly output. – computingfreak Jul 3 at 0:34

List files by size ascending would be:

ls -lSr

The options are:

  • l: long, shows detailed user,group,other attributes, date, etc.
  • S: orders listing by size (descending by default)
  • r: reverses order of listing
share|improve this answer
Would you mind explaining the options to improve the quality of the answer? – Rui F Ribeiro Jun 29 at 18:53

As a variation of the original question, if you want to see the cumulative size of files in the subdirectories:

find ${1:-.} -maxdepth 1 -type d -exec du -sm {} \; | sort -nr

The sizes will be displayed in Megabytes ( the m in du -sm). Other values accepted by du are -k for kilobytes, -g for gigabytes. Using -h for human-readable display is not possible because it will break sorting.

Here is a version that uses sed to append the M for megabyte:

find ${1:-.} -maxdepth 1  -type d  -exec du -sm {} \; | sort -nr | sed -E 's/^([0-9]+)/\1M/g'

The directory to display is set via ${1:-.} which will use the first command line argument if provided, or use the current directory if called without arguments.

NOTE: This can take a long time with a lot of files. The option -type d will only list subdirectories and exclude files in the current folder; if you also want to see the files in the current folder then remove it.

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.