Find large files on Linux: 5 Command-line Examples

find large files, linux, big files, largest files

In this blog post, we’ll walk you through five command-line examples that can help you pinpoint the largest files in your Linux system.

When it comes to Linux system administration, monitoring disk usage is a critical task. But how do we find the largest files eating up valuable disk space? It’s easier than you might think! With just a few commands, you can navigate your directories and identify those pesky storage hogs.

1. Using du and sort Commands

The du (Disk Usage) command, in combination with the sort command, is a simple and efficient way to identify large files. The following command will display the top 10 largest files in the current directory and its subdirectories:

du -a . | sort -n -r | head -n 10

This command breaks down as follows:

  • du -a . lists the file sizes for all files in the current directory and its subdirectories.
  • sort -n -r sorts the output numerically and reverses the order to show the largest files at the top.
  • head -n 10 limits the output to the top 10 lines.

2. Using the find Command

The find command is very versatile and can be utilized to find large files. The following command will find all files larger than 100MB in the /home directory:

find /home -type f -size +100M

3. The ncdu Command

If you have access to install packages, the ncdu (NCurses Disk Usage) command is a fantastic tool. It gives a detailed and navigable overview of data usage in directories. Install it and run as follows:

sudo apt-get install ncdu
ncdu /

The ncdu / command will scan the entire filesystem. Feel free to replace / with any directory path you’d like to scan.

See also  BlueStacks Linux (Android): A Step-by-Step Guide

4. Combining ls and sort

For quick directory scans, ls and sort combination works like a charm. The command below will display files based on size in descending order:

ls -lSh | head

The -lSh flag tells ls to provide a detailed list (-l), sort by size (-S), and show sizes in human-readable format (-h). The head command will limit the output to the top 10 files.

5. Using awk with find

For more control over the output, combine awk with find. The command below finds files larger than 50MB and displays their size and name:

find / -type f -size +50M -exec ls -lh {} \; | awk '{ printf "%s %s\n", $5, $9 }'

How do I find files greater than 100MB in Linux?

You can use the find command in Linux to find files greater than 100MB. The following command will find all files that are larger than 100MB in the entire system:

find / -type f -size +100M

Here’s a breakdown of the command:

  • find is the command used in Unix and Linux systems to search and locate the list of files and directories based on conditions you specify for files that match the arguments.
  • / is the directory to start from. In this case, we start from root, which covers the entire filesystem.
  • -type f specifies that you’re looking for files.
  • -size +100M specifies the size condition. In this case, it’s looking for files larger than 100MB.

You can replace / with any specific directory you want to look in. For instance, if you wanted to look only in the /home directory, you would use the following command:

find /home -type f -size +100M

This will display a list of all files in the /home directory (including subdirectories) that are larger than 100MB.

See also  How to Append Files in Linux: A Comprehensive Guide

How do I delete the largest files in Linux?

Before you proceed with deleting large files in Linux, ensure that these files are not crucial to system operations. Always backup important data before any major deletion task.

The process to delete large files involves identifying these files first and then deleting them. Simply add the -delete parameter to the above example.

find /home -type f -size +100M -delete

This command will find and immediately delete files larger than 100MB from the /home directory and its subdirectories.

These Linux commands should empower you to find the largest files lurking in your disk space. Remember, before deleting any files, ensure they are not crucial to system operations. Always backup important data before any major deletion spree!

This article is part of our Linux system administration tips series. Check out these related articles:

5 thoughts on “Find large files on Linux: 5 Command-line Examples”

  1. For unix, you can also use below command – It will give you the output of 30 largest utilizing files :-

    du -h | sort -rn | head -30

    Accordingly you can decide, which files to be retained or housekeeped.

    PS – The command needs to be fired from within the directory.

Leave a Comment