How to Find Large Files on Linux?

In this article, we will explore several methods that you can use to locate and isolate large files within a specific directory in Linux. Be sure to follow the steps carefully to avoid any issues.

Large File

While there are numerous ways to find large files on Linux, we have selected some of the most convenient methods for you.

Method 1: Using the du Command

In Linux, there are several commands available to help you locate and sort files in a directory based on their size and location. In this method, we will combine a few commands to sort files in a specific directory according to their size.

  1. Press the “Ctrl” + “Alt” + “T” keys at the same time to open the terminal.
    Pressing “Ctrl” + “Alt” + “T”
  2. Type the following command and press “Enter” to log in as a root user.
    sudo -i
  3. Enter the following command and press “Enter” to find the largest files in the directory.
    $ sudo du -a /dir/ | sort -n -r | head -n 20

    Note: The du command is used to calculate file sizes, sort arranges the output based on size, and head limits the output to the 20 largest files.

  4. You can also use this command to perform the same task:
    $ sudo du -a / 2>/dev/null | sort -n -r | head -n 20
  5. Linux will now display the top 20 largest files in the specified directory.

Method 2: Using the Find Command

If you want to directly locate the largest file itself, rather than just the directory hosting it, you can use the “find” command to generate the required output.

  1. Press the “Ctrl” + “Alt” + “T” keys simultaneously to open the terminal.
  2. Type the following command and press “Enter” to log in as a root user.
    sudo -i
  3. Enter this command and press “Enter” to locate the largest file on your computer.
    $ sudo find / -type f -printf "%s\t%p\n" | sort -n | tail -1
  4. Next, type the following command and press “Enter“.
    $ find $HOME -type f -printf '%s %p\n' | sort -nr | head -10
  5. These commands will list the largest files available.
ABOUT THE AUTHOR

Kevin Arrows


Kevin Arrows is a highly experienced and knowledgeable technology specialist with over a decade of industry experience. He holds a Microsoft Certified Technology Specialist (MCTS) certification and has a deep passion for staying up-to-date on the latest tech developments. Kevin has written extensively on a wide range of tech-related topics, showcasing his expertise and knowledge in areas such as software development, cybersecurity, and cloud computing. His contributions to the tech field have been widely recognized and respected by his peers, and he is highly regarded for his ability to explain complex technical concepts in a clear and concise manner.