How do I list files by size? To list all files and sort them by size, use the -S option. By default, it displays output in descending order (biggest to smallest in size). You can output the file sizes in human-readable format by adding the -h option as shown. And to sort in reverse order, add the -r flag as follows.
How do you sort ls by size? To list or sort all the files by size, use the -S option, that tells the ls command to sort the file listing by size and the -h option makes the output a human-readable format. In the following output, the largest files are shown in the beginning.
How do I list the top 10 large files in Linux?
- Open the terminal application.
- Login as root user using the sudo -i command.
- Type du -a /dir/ | sort -n -r | head -n 20.
- du will estimate file space usage.
- sort will sort out the output of du command.
- head will only show top 20 largest file in /dir/
How do I search by size in Linux?
- ls -l filename #check size of the specified file.
- ls -l * #check size of all the files in the current directory.
- ls -al * #check size of all the files including hidden files in the current directory.