How to Find Large Files on Linux?

Linux’s Family of operating systems is a group of open-source operating systems that are based on the Linux kernel that was developed and released in 1991. Linux is one of the most popular operating systems among software developers and professional users. In this article, we will discuss some methods that can be used to locate and isolate Large Files in a particular directory. Make sure to follow the steps carefully and accurately in order to avoid conflict.

Large File

How to Find Large Files on Linux?

There are a lot of methods which can be used to find large files on a Linux but we have only compiled some of the most convenient ones below.

Method 1: Through du Command

There are a couple of commands in Linux that can help the user to find and sort certain files in a directory depending upon their size and location. In this step, we will be combining a few commands to sort the files in a particular directory according to their size. For that:

  1. Press the “Ctrl” + “Alt” + “T” buttons simultaneously to launch the terminal.
    Pressing “Ctrl” + “Alt” + “T”
  2. Type in the following command and press “Enter” to login as a root user.
    sudo-i
  3. Type in the following command and press “Enter” to find the largest file on the directory.
    $ sudo du -a /dir/ | sort -n -r | head -n 20

    Note: du is used to calculate the file size, the “sort” will list the output of the du command according to the sizes and the “head” limits the response to only the 20 largest files.

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

Method 2: Using Find Command

If you want to directly find the largest file and not the directory which hosts it, you can combine the “Find” command to list the required output. For that:

  1. Press the “Ctrl” + “Alt” + “T” buttons simultaneously to launch the terminal.
  2. Type in the following command and press “Enter” to login as a root user.
    sudo-i
  3. Type in the following command and press “Enter” to find the largest file on the computer.
    $ sudo find / -type f -printf "%s\t%p\n" | sort -n | tail -1
  4. After that, type in 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.
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.