Hello folks, in this article, we will discuss how to sort files by size in Linux. Most of you are familiar with the ls command which is used to list files in the current working directory. But by using some parameters with the ls command, We can sort the files by name, size, modification time, etc along with the system files that are not shown by default. In this tutorial, We are using Ubuntu 20.04 LTS.
Sort Files By Size in Linux Terminal
To list all files in the current directory, Open a terminal window by pressing Ctrl+Alt+T and enter the following command,
In the above command, use
-l parameter to list all files in a long list format and
-a to show hidden files.
To list and sort all files by size in descending order(by default), use
-S parameter or enter the following command,
The files are now listed in descending order by file size. To show the size in human-readable format, use
To sort the files by size in ascending order, use
That’s all for now, we discussed how to sort all files by size in Linux in both the order i.e. ascending and descending. We can also sort files by name, date, time, etc using the ls command. Thank you for reading!