How to list files by size in linux

The files size of the files return by this command are in KB.

Run the following command:


ls -sk *.txt | sort -nb -r

The files size of the files return by this command are in KB.

Example:

This example runs ls -al to list all the files in the current directory. The files are listed by name, the order they are defined on the file system. File2 is the smallest file and file3 is the biggest file.
The command ls -sk *.txt | sort -nb -r is then called, the files are returned by size and their size in KB is shown. File3 is first then file1 and file2.


$ ls -al
total 153
drwxrwx---+ 1 Olivier None      0 Aug 13 14:55 .
drwxrwx---+ 1 Olivier None      0 May 21 16:30 ..
-rwxrwx---+ 1 Olivier None  26961 Aug 13 14:45 file1.txt
-rwxrwx---+ 1 Olivier None    216 Aug 13 14:47 file2.txt
-rwxrwx---+ 1 Olivier None 107844 Aug 13 14:55 file3.txt

$ ls -sk *.txt | sort -nb -r
108 file3.txt
 28 file1.txt
  1 file2.txt

References:

ls command

Recent Comments