brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: find -maxdepth 1 searches one folder without going into the subfolders

Find
~/tips/tip-find-maxdepth-one-level

find /etc -maxdepth 1 -type f -name '*.conf'

Limits how many directory levels find goes down.

A plain find walks every level below. For one directory, I limit the depth.

find /etc -maxdepth 1 -type f -name '*.conf'
find /srv -mindepth 1 -maxdepth 1 -type d

-maxdepth 1 looks at the starting directory only, and -mindepth 1 leaves out the starting point itself. That second command lists the direct subfolders. Put both options in front of the other tests, because GNU find prints a warning when a global option comes after a test such as -name. It is also a safe way to build a list of folders for a loop in a script.

Further reading: find manual page

More Find tips find / -maxdepth 1 -fstype proc find /backup -name '*.gz' ! -exec gzip -t {} \; -print 2>/dev/null find /srv/downloads -type f -size +100M -size -1G -exec ls -lh {} + find /srv/data -depth -print find /srv -xdev -samefile /srv/downloads/movie.mkv All Find tips (46) All topics

Link