fbpx

When you have a server with 1TB of disk space and your storage is 80% full, it is important to find out which files(largest files) are taking up the most space on your system. This can be done by identifying the biggest files on your system and deleting or moving them to free up some space.

To find the largest files on your system, you can use a command line tool such as “du” (short for disk usage). The “du” command shows the size of each file and directory in the current directory and its subdirectories. By using some options with the “du” command, you can sort the output to show the largest files at the top.

Find the largest files in Linux

Here’s an example command that you can use to find the biggest files on your system:

du -ah / | sort -rh | head -n 20
How to find the largest files in Linux

This command will show the 20 biggest files on your system, sorted by size. The “du -ah /” part of the command tells “du” to show the size of all files and directories starting from the root directory (“/”). The “sort -rh” part of the command sorts the output in reverse numerical order, so the largest files appear at the top. Finally, the “head -n 20” part of the command limits the output to the 20 largest files.

Once you have identified the biggest files on your system, you can decide what to do with them. If you no longer need the files, you can delete them to free up some space. If the files are important but not frequently used, you can move them to an external hard drive or cloud storage to free up space on your server.

It’s a good idea to periodically check for large files on your system and delete or move them as necessary to avoid running out of disk space.

Find the largest files in Linux using find

Here’s an example command using the “find” command to find the largest files on a Linux system:

find $HOME -type f -printf '%s %p\n' | sort -nr | head -10

Please take note that you can either use “/” to search the entire system or replace “$HOME” with the directory you have selected.

How to find the largest files in Linux

2 Comments

dlatikay · January 6, 2024 at 11:52 AM

if the disk is full, and therefore this command would be useful to find large files to delete or move to free up space, then this command fails miserably:

sort: write failed: /tmp/sortUxBoYe: No space left on device

Is there a variant which does not itself need space on the disk?

Linux: How To Search Text In A PDF File Via Command Line - Virtono Community · September 15, 2023 at 4:37 PM

[…] this tutorial, we will explain how to search text in a PDF file using Linux command-line options. One of Linux’s many advantages is its command-line interface (CLI), which allows users to […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.