Find large files and directories in Linux with ease and ensure your system disk is well optimized for proper functioning. Knowing about various software maneuvers is crucial for every Linux administrator, and that’s what the following article is all about.
It might sound like a complex technical encounter, but finding large files and directories in Linux is relatively simple, provided you know the appropriate approach. To help you with that, here are the best ways to employ and find large files and directories in Linux within minutes.
Invoking the find Command
One of the most straightforward ways to locate or find large files and directories in Linux is by invoking the find command. If you’ve no idea about this command, just how it’s named, find is meant to help users search files located in a directory hierarchy.
For instance, you want your system to filter and list all the files that are more than 100MBs. To do that, you do as follows:
Launch the Terminal by using the “Ctr;+Alt+T” key combination
Run the command in the following format:
$ find / -xdev -type f -size +100M
Alter the values according to your needs and find large files and directories you’re looking for with ease.
find command is a flexible tool that allows suitable attachments for grabbing a more detailed result. You can include different parameters and diversify the output every time.
Suppose you want to look at the 5 of the largest files that a particular directory holds. In that case, employ the head
The command should look something like this:
$ find /usr -type f -printf "%s %p\n" | sort -rn | head -n 5
Find Large Files and Directories in Linux Using the ls Command
ls command, you’re looking at another brilliant utility to find large files and directories in Linux. The ls is a shell command that operates for listing all sorts of directory contents in a very adaptable manner.
Although you can use the
ls flag in various ways, the most straightforward approach of listing the heavily weighed files is by running the following command:
$ ls -alhS
Invoking the command as mentioned above will present the list of the files within the current working directory in the descending order of their sizes.
Using the ls command alongside the
-r flag can help display the sizes of the file. The dedicated command for such action looks something like this:
$ ls -lhtr
Also, the command allows users to specify the desired location for which they want their system to display the file sizes. To do so, input the following:
$ ls -lhtr /[desired location]
Getting the List of The Biggest Files
Like the find command, the
ls command packs the utility for quickly accessing the list of the biggest files located within a directory. All you need to do is run the following command.
Make sure you replace the value after
-n flag and specify the desired length of the list.
Print and Find the Large Files and Directories in Linux: gt5 Tool
Having talked about those two amazing methods already, it is time I walk you through another super-efficient tool that I’m pretty sure you haven’t heard about.
The tool named gt5 brings a promising way to find large files in Linux and even check the sizes seamlessly. But before you can start using it, getting the utility installed on your system is a crucial step.
Installing the gt5 Tool
To install the gt5 tool on your Linux system, you must employ the
$ sudo apt install gt5
Using the gt5 Tool
Once the installation process is done, you’re now ready to use the gt5 tool and find large files and directories in Linux by running the following commands:
$ gt5 /var
Remember, you can always specify the required directory to make the file searching process much easier.
Making Use of the du Command to Find Large Files and Directories
Abbreviated as disk usage, the du command shelters great usability in the storage section. The command offers a lot, from reporting directory sizes to tracking down space hogs, but let’s stick to finding large files and directories for now.
du command on its own is not that helpful in locating large files. However, when associated with options like sort, head, and even find, you get your hands on what you’re after. Moreover, you can invoke the
-h parameter and demand an output corresponding to a more human-readable form.
After that, you can use the
cd command, navigate to the required directory, and check the files.
$ cd /var/log/ $ du -hsx* | sort -rh | head -n 5
The Disk Usage Analyzer Method
Using a disk analyzer to find large files and directories in Linux is preferred by many. Although you’ll find several utilities, I recommend using the Ncdu disk analyzer that features the Ncurses interface. The reason we suggest this is that the tool is home to next-level efficiency with basic level functional ability.
Using the Ncdu disk analyzer is simple, but you’ll need to get it installed first. For that, launch the Terminal and run the following command:
$ sudo apt install ncdu
Once done, get inside the tool by using the
$ ncdu command
You’ll then see that the tool will start updating the disk of the concerned system and come up with the results.
The list displays the files in descending order, with the largest file sitting at the very top.
That pretty much wraps up the resources you need to find large files and directories in Linux. In this article, I’ve uncovered five brilliant ways to locate files within your system, and that too with next-level flexibility. Which one has been your personal favorite? Let us know in the comment section below.
If this guide helped you, please share it.