How to sort files in folder from the biggest to smallest

Written by Administrator on Saturday May 2, 2020

Command ls in Linus is very powerful and you can list files any way you want using proper parameters. In case we want to sort files in a folder by size descending, we run a following command:

$ ls -S

This command show all files in a folder and list them descending by file size, but there's a problem, which we will explain in an article below. It's good to write about commands and outputs, but the best way, from my point of view, is to show everything on a real example (I tried it on openSUSE Linux, but ls is a command, which works in every Linux distro, so don't be afraid something will work different way on your system.

Let's take a folder with linux .iso distributions:

$ ls

Now, let's try ls command with different flags:

$ ls -S

This command sorts files in a folder by size:

The problem is, that we don't see file sizes in this output. We can change it, just run:

$ ls -l -S

sorting files by size in a folder in Linux

Now we have files sorted by size in a selected folder and moreover, we have file sizes shown.

Category: linux Tags: ls working-with-files sort