Flatten Nested Folders with find and mv

Move every file from all subfolders up into the top-level folder in one command.

macOSFilesMedium risk
Run find -mindepth 2 -type f -exec mv -n {} . to lift all nested files into the current folder.

01Command

Command
$ 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

RiskMedium risk
!Warning: Two subfolders with the same filename collide — the -n flag leaves the extra file in place instead of destroying it.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • find – Walk a file hierarchy
    ss64.com · technical · 2026-09-17
    Evidence: 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