How to Find Largest Files in a Directory with ls command

One of the advantages in having bigger hard drives is that we hardly worry about the available space. However, there comes a time, you want to clean up unwanted files and want to free up space really quick.

One way to do that is to find the largest files and remove them if they are no longer needed. One can easily find the largest files in a specific directory right from your terminal. The most easiest way to do it is to use “ls” command in the terminal and sort by size in human readable form using

ls -lSh | more
  1. The option “l” lists each file in a separate line with more info about the file/directory
  2. S” sorts the files in the order of biggest to smallest
  3. h” gives the output in human readable form (like MB and GB)

Here is an example output on finding the largest files in a directory. We can see that files are in descending order in that directory.

Find Largest Files in a Directory
Find Largest Files in a Directory

If you want to list only the specific type of files, like pdf, then you can use the “ls” command as

ls -lSh *.pdf

This will list pdf files (ignoring other file types) in descending order by their size.