I would like one command to just write "flatten" with no arguments and it would have sane default behavior.

  • This cmd from the first post you linked to needs the /directory as the argument: find /directory -mindepth 2 -type f -exec mv -f '{}' /directory ';'. How do you want to handle that? Dec 11, 2023 at 17:39
  • Perhaps you intend to run from the dir you want to flatten? Dec 11, 2023 at 17:44

1 Answer 1


Assuming you have a *NIX system (UNIX/Linux/macOS/etc).

Run this once per terminal session, or put this into your ~/.bashrc file:

alias flatten='find . -mindepth 2 -type f -exec mv -f {} . ";"'

Then run the commands below. These commands can be run repeatedly without side effects. First, cd into the directory you would like to flatten, then flatten the files:

cd /dir/to/make/flat


Files with identical names but different paths will overwrite each other.

See also:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.