Understanding Maxdepth Mindepth Depth In Linux Find Command

Table of Contents

Find command on Linux is a very powerful tool to search files or directories. We can use maxdepth/mindepth to limit down the search to specific depth levels.

How to Use Depth In Find Command

We can combine two options together to limit the search only between max/min depths. On Centos, there is no option for -depth. We can use -maxdepth n -mindepth n to search files or directories only under n depth level.

Learning Maxdepth and mindepth

The descriptions of maxdepth and mindepth are in the following:

  • maxdepth levels – Descend at most levels (a non-negative integer) levels of directories below the command line arguments. -maxdepth 0 means only apply the tests and actions to the command line arguments.
  • mindepth levels – Do not apply any tests or actions at levels less than levels (a non-negative integer). -mindepth 1 means process all files except the command line arguments.


10 Linux Find Exec examples – Advanced Part

Examples of Depth in Find Command

We can use the following examples to limit the depth level in Linux find command.

# find /etc -maxdepth 2 -name passwd
# find /etc -mindepth 1 -name passwd
# find /etc -mindepth 1 -maxdepth 1 -name passwd
# find /etc -mindepth 1 -maxdepth 2 -name passwd

6 Examples to Find File By Name in Linux

Related Post:

Linux Find Exec examples – Advanced Part

5 Examples for Linux Find command

Find File By Name in Linux

20 Advanced Linux Find Command Examples

How to use Find Command in Linux

3 Ways to find the largest files in Linux

10 Linux Find Exec examples – Advanced Part is dedicated to providing comprehensive information on using Linux.

We hope you find our site helpful and informative.

Learn More


RHCSA Practice Exam

RHCSA Practice Exam A General Notes Here are some tips to ensure your exam starts with a clean environment: You do not need external servers

Read More »