Flatten Nested Folders with find and mv
Move every file from all subfolders up into the top-level folder in one command.
01Command
$ cd ~/Desktop/MessyFolder && find . -mindepth 2 -type f -exec mv -n {} . \;02What it does
-mindepth 2 skips the top-level files so they stay put, and mv -n refuses to overwrite if two subfolders contain files with the same name — those stay behind with duplicates reported when you run it without -n. Replace -type f with -iname "*.jpg" -type f to flatten only certain file types, and clean the empty leftover folders with find . -type d -empty -delete afterwards.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- find – Walk a file hierarchyEvidence: find -mindepth 2 -type f matches files below the top level; -exec mv -n {} . moves each one up without overwriting.
Last verified: 2026-09-18 · Category: Files & Folders
06Related solutions
List the biggest files in your home folder that are eating disk space.
Make Finder display .pdf, .docx, .png and every other extension at all times.
List every open file descriptor — files, directories, and network sockets — per process.