Linux ls Command Sort Files By Size

To sort the output of the “ls” command by file size, you can use the “ls” command with the “-S” option. The “-S” option sorts the files and directories by size, with the largest files listed first.

Here’s an example of how to use the “ls” command to sort files by size:

ls -lS

This will display a list of the files and directories in the current directory, sorted by size in descending order. Each line in the output will show the file or directory name, its size, and other information such as the date and time of the last modification, and the owner and group of the file.

You can also sort the files in ascending order by size by using the “-r” option to reverse the sort order:

ls -lSr

This will display a list of the files and directories in the current directory, sorted by size in ascending order.

Leave a Comment