Limit find depth

Snippet

Limit the depth of find for checking only some subdirectories instead of all of them by using -maxdepth.

You can also use -mindepth to sandwich directory levels.

# same as finding all files one level down, similar to "ls ./??*"
find . -maxdepth 1 -type f
 
# find all sub-subdirectories in the current directory
find . -maxdepth 2 -mindepth 2 -type d

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.