How to Limit Search by Minimum Depth in Ubuntu (find -mindepth)

The Shallow Exclusion Problem

When executing complex searches in Ubuntu Linux, you frequently need to ignore files sitting in the immediate parent directory and only search deep within nested subfolders. For example, if you are searching /var/www/ for a file named index.php, but you absolutely do not want the search to return the master /var/www/index.php file at the top level, you must instruct the search engine to skip the surface layer entirely and only begin its evaluation inside the deeper subdirectories.

Using the find Command with -mindepth

The Linux find command utilizes the -mindepth flag to explicitly set the minimum structural level at which the search algorithm is allowed to begin matching files.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To search the /var/www/ directory for index.php, but strictly ignore any files located directly inside the top-level /var/www/ folder, type the following command exactly:
  3. find /var/www/ -mindepth 2 -name "index.php"
  4. Press Enter.

Depth Forensics

The syntax utilizes a numeric integer following the flag. -mindepth 1 represents the starting directory itself. By setting -mindepth 2, you are forcing the find algorithm to completely ignore the surface level and only begin evaluating files that are nested at least one folder deep (e.g., /var/www/html/index.php or /var/www/backup/index.php). This command is an absolute necessity for system administrators attempting to isolate duplicate configuration files buried deep within an application stack while explicitly excluding the master configuration file sitting at the root.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.