Sorting by size
First of all command ls
has option -S
From man ls
-S sort by file size
So proper command is:
ls -S
sort
command is for sorting lines of text file:
From man sort
:
-S, --buffer-size=SIZE
use SIZE for main memory buffer
SIZE is an integer and optional unit (example: 10M is 10*1024*1024). Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).
That's why you are getting error: sort : option requires an argument -- ´S´
. Use ls -S
for sorting file by size!
You can also use du
command with some arguments and use sort
I use the following:
$ du -hsc /path/to/file
From man du
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
-s, --summarize
display only a total for each argument
-c, --total (I USE IT FOR EXTRA INFO)
produce a grand total
To sort
$ du -hsc /path/to/file | sort -h
From man sort
-h, --human-numeric-sort
compare human readable numbers (e.g., 2K 1G)