ls commands

If we would like to list all files in the order of big to small (descending) in size, we can easily do it using the ls command.

The file list can be in the root directory or inside any directory. Following is the command:

$ ls -lS // Capital S. Sort by file size

If we want to see it in Byte, Kilobyte, Megabyte, Gigabyte, Terabyte, and Petabyte in order to reduce the number of digits to three or less using base 2 for sizes.

$ ls -lSh // option h. 

If we want to list it in the reverse order to get reverse lexicographical order (ascending order), we can try the following command:

$ ls -lShr // option r

To exclude directories and provided none of the file names or symlink targets contain newline characters.

$ ls -lSh | grep -v '^d'