Find Large Files in Linux

Want to find large files in Linux? Running out of disk space and need to perform a disk cleanup? It is always a good idea to keep tabs on your overall file space usage and be aware of which files and directories are taking up the most space on your Linux system. Especially after you've installed a lot of software and your disk space begins to fill up. Once you know what the largest files are, you can perform a disk cleanup to remove any unnecessary files in order to make space for new programs and files.

How to Find Large Files in Linux

List File Size Linux

You can list contents of the current directory by size in descending order in Linux by using the ls command followed by arguments -Ssh.

ls -Ssh

Find Large Files in Linux using the size option

To find large files in Linux, you can use the find command with the -size option. For example, to use a Linux command to find files larger than 100 gigabytes (100G) in the current directory and its subdirectories,

  1. Open up a terminal Ctrl+Alt+T
  2. Next, type cd and then press Enter to change directory to where you would like to start your base search for the largest files.
  3. Type the following and then press Enter;
find . -type f -size +100G

The find command will display a list of files that match the specified criteria. It starts from the current directory (.) and searches for regular files (-type f) that are larger than 100 Gigabytes (-size +100G). Adjust the size value to suite your needs. If you want to limit the search to a specific directory, simply replace . with the path to that directory. For example;

find /path/to/directory -type f -size +100G

Replacing "/path/to/directory" with the actual directory path you want to search in. The rest of the command remains the same.

How to remove large files in Linux

To remove large files in Linux, you can use the find command in combination with the rm command. Here's an example command that finds files larger than 100 Gigabytes (100G) in the current directory and its subdirectories and deletes them:

find . -type f -size +100G -exec rm {} +

This command starts from the current directory (.) and searches for regular files (-type f) that are larger than 100 Gigabytes (-size +100G). The -exec option is used to execute the rm command on each file that matches the criteria. The {} represents the file name, and the + at the end ensures that multiple files are passed to a single invocation of rm (which is more efficient than invoking rm for each file separately).

Please be cautious when using the rm command, as it permanently deletes files without any confirmation. Make sure to double-check the files you are deleting before executing the command.

Use find + disk usage (du) + head Linux commands to find largest files

Here's another way from Ubuntu Linux to find large files using the find + disk usage (du) + head commands from an open terminal.

  1. From the terminal, change to the directory to where you would like to start your base search for the largest files.
  2. Type the following and press Enter;
    find -type f -exec du -h {} + | sort -hr | head -8

    Linux find large files

The files are located and sorted by largest file size first and then displayed in the terminal window.

How find + du + head work to locate large files in Linux

The Find command works by first finding all files starting at the base directory including its sub-folders. The files are then probed for their disk usage via du, set to display size in -h (human readable format). The files are then sorted in -h (human readable format) in -r (reverse order) largest first. Finally head is run to output the number of results (-#) , in lines that we want to return. In this example 8.

Note: You will get permission denied errors, if the user running the command doesn't have permission to access a file.

This concludes the simple tutorial to find large files in Linux.