Recursively listing a directory tree exposes every nested file and folder below a starting path, which is useful when checking application content, auditing backup scope, or confirming what exists before cleanup work. A full recursive view is also the quickest way to spot hidden files that would be missed by a shallow directory listing.
In Linux, find is the most reliable built-in tool for this job because it walks the directory tree directly and can print every path, only files, only directories, or cleaned-up relative names from the same command flow. Unlike ls -R, it also includes hidden entries such as dotfiles without needing a separate display mode.
Recursive listings can become noisy on large trees or when the starting path includes protected directories, mounted volumes, or network storage. Start from the narrowest useful directory, add -maxdepth when only the first few levels matter, and add -xdev when a scan from a mount root such as / or /var should stay on one filesystem.
Steps to list files and folders recursively in Linux:
- Print every path below the starting directory to get the full recursive view.
$ find /srv/recursive-demo /srv/recursive-demo /srv/recursive-demo/logs /srv/recursive-demo/logs/app.log /srv/recursive-demo/logs/app.log.1 /srv/recursive-demo/README.md /srv/recursive-demo/.hidden-root /srv/recursive-demo/docs /srv/recursive-demo/docs/notes-2025.txt /srv/recursive-demo/docs/archive /srv/recursive-demo/docs/archive/notes-2024.txt /srv/recursive-demo/config /srv/recursive-demo/config/app.conf /srv/recursive-demo/config/.env
find walks the tree directly, so hidden entries such as /srv/recursive-demo/.hidden-root and /srv/recursive-demo/config/.env appear without an extra flag.
- Skip the starting path and print relative names when the list should be easier to scan or compare.
$ find /srv/recursive-demo -mindepth 1 -printf '%P\n' | sort .hidden-root README.md config config/.env config/app.conf docs docs/archive docs/archive/notes-2024.txt docs/notes-2025.txt logs logs/app.log logs/app.log.1
-mindepth 1 omits the root path itself, and %P removes the starting-path prefix from each printed entry.
- Limit the recursive list to regular files when only file paths matter.
$ find /srv/recursive-demo -type f -printf '%P\n' | sort .hidden-root README.md config/.env config/app.conf docs/archive/notes-2024.txt docs/notes-2025.txt logs/app.log logs/app.log.1
-type f excludes directories, symlinks, device nodes, and other non-regular entries.
- Limit the recursive list to subdirectories when the directory structure matters more than the files inside it.
$ find /srv/recursive-demo -mindepth 1 -type d -printf '%P\n' | sort config docs docs/archive logs
Keeping -mindepth 1 in the directory-only view removes the starting directory from the result set.
- Stop descending after the required number of levels when the top of the tree is enough.
$ find /srv/recursive-demo -maxdepth 2 -mindepth 1 -printf '%P\n' | sort .hidden-root README.md config config/.env config/app.conf docs docs/archive docs/notes-2025.txt logs logs/app.log logs/app.log.1
-maxdepth 2 keeps the listing from descending into docs/archive/notes-2024.txt because that file sits one level deeper than the limit.
- Add metadata when the recursive list also needs permissions, owners, sizes, or timestamps.
$ find /srv/recursive-demo -ls 2905320 4 drwxr-xr-x 5 root root 4096 Apr 14 01:23 /srv/recursive-demo 2905324 4 drwxr-xr-x 2 root root 4096 Apr 14 01:23 /srv/recursive-demo/logs 2905328 4 -rw-r--r-- 1 root root 7 Apr 14 01:23 /srv/recursive-demo/logs/app.log 2905327 4 -rw-r--r-- 1 root root 8 Apr 14 01:23 /srv/recursive-demo/logs/app.log.1 2905331 4 -rw-r--r-- 1 root root 6 Apr 14 01:23 /srv/recursive-demo/README.md ##### snipped #####
Use -ls for a human-readable audit, and use -print0 instead of newline output when the result will be passed to another command that must handle unusual file names safely.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
