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.
Simply use something like:
This will sort files in size.
To exclude directories:
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
On my system this only shows regular files.
To add recursion I would leave the sorting of the lines to the
If you do need the full path of the files, use something like this:
You could use something like find and sort.
If the file names may contain newline characters, with GNU find and GNU sort:
With zsh and GNU ls:
(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:
If you just want the list of files and not the detailed output, just do:
If you want to include hidden files (whose name starts with a dot, except
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
This "finds" all files in the current working directory (
Try these, it works fine for me.
Not perfect answer though but works to some extent
I wrote something to this extent a while back. You could pass an argument to specify how many files to list, or just type
Adding to delh's answer and Stéphane Chazelas' comment...
The commands below will provide the desired output.
Human-readable, on GNU's sort / Linux:
In kilobyte units, on BSD / OSX / others:
For BSD / OSX, also see http://unix.stackexchange.com/a/188375/82895.
List files by size ascending would be:
The options are:
As a variation of the original question, if you want to see the cumulative size of files in the subdirectories:
The sizes will be displayed in Megabytes ( the
Here is a version that uses
The directory to display is set via
NOTE: This can take a long time with a lot of files. The option