> ## Content Index
> Fetch the complete content index at: https://snubmonkey.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Using 'find' to Locate Large Files in Linux.
- URL: https://snubmonkey.com/using-find-to-locate-large-files-in-linux/
- Published: 2025-06-23T09:14:41.000Z
- Updated: 2025-06-24T15:08:10.000Z
- Description: In Linux, the 'find' command helps locate large files that may be consuming disk space. It's useful for admins or users needing to identify files of a specific size or larger, especially when cleaning up a system or managing disk usage.
- Author: yannick Coffi
- Tags: linux 🐧, how to 🪄, terminal

When managing storage on a Linux system, it's crucial to identify large files that may be taking up valuable disk space. The `find` command is a versatile tool that lets you search for files based on various criteria, including `size`. In this post, we'll explore how to use `find` to locate files larger than a specified size and how depth control can enhance your searches.

## **Finding Large Files Recursively**

To find all files larger than 20MB in the current directory and its subdirectories, use the following command:

```zsh
$ find . -type f -size +20M
```

  
**Breakdown & Explanation**:

- `.` → Start the search from the current directory.  
To search the entire system, replace `.` with `/` (use `sudo` to elevate privileges if necessary)
- `-type f` → Search for files (not directories).
- `-size +20M` → Find files larger than 20MB.

This command runs **recursively** by default, meaning it will search through all subdirectories.  

## **Limiting Search Depth with `-maxdepth`**

Sometimes, you may want to limit the search to avoid deep directory traversal. The `-maxdepth` option controls how deep `find` will look.

###   
Example: Searching Only in the Current Directory

```zsh
$ find . maxdepth 1 -type f -size +20M
```

  
**Breakdown & Explanation**:

- `-maxdepth 1` → Restricts the search to the current directory only (does not check subdirectories).
- Useful when you only need to analyze top-level files.

### Example: Searching Two Levels Deep

```zsh
$ find . maxdepth 2 -type f -size +20M
```

  
**Breakdown & Explanation**:

- `-maxdepth 2` → Limits the search to two levels deep (i.e., the current directory and its immediate subdirectories).
- Helps narrow results while still checking some nested folders.

##   
**BONUS ‼️:** 
**Sorting Large Files by Size**

To list large files sorted by size, you can combine `find` with `du` and `sort`:  

```zsh
$ find . -type f -size +20M -exec du -h {} + | sort -hr
```

This will display the largest files first, making it easier to identify space hogs.  

**Breakdown & Explanation**:

• `find .` → Search in the current directory (.) and all subdirectories (recursively).  
• `-type f` → Look for **files** only (not directories).  
• `-size +20M` → Find files **larger than 40MB**.  
• `-exec` → Execute a command on the found files.  
• `du -h {}` → Run du (disk usage) in human-readable format (-h) on each file ({} represents each file found).  
• `+` → Runs du efficiently by grouping multiple files in a single command execution (faster than \\; which runs du separately for each file).  
• `|` → Pipe output from du to sort.  
• `sort -hr` → Sort output **numerically by size**, in **descending order**:  
• `-h` → Human-readable sort (e.g., 1G, 500M, 20K).  
• `-r` → Reverse order (largest files appear first).

  
The `find` command is an indispensable tool for identifying large files in Linux. By default, it searches **recursively**, but with the `-maxdepth` option, you can limit the depth of your search to refine results. Mastering these options can help you manage disk space efficiently.  

  
We hope you found these insights useful!