Let's say I have a path like this


I want to move all files inside sub folders of /x/ to /x/ at the same time. Is this possible?

I'm on Ubuntu 16.04.

The subfolders have different names, and I want to move all files inside a subfolder no matter the depth, to /x/. Also it's possible that I'll have spare files inside /x/ that are not in any sub folder. No files should go above /x/ no matter what.


Move to target folder and execute:

find . -mindepth 2 -type f -print -exec mv {} . \;

with -mindepth 2 it will search recursively without including the current directory.

  • It will search inside any subfolders inside x given your example... – marc Apr 11 '17 at 10:52
  • With GNU tools find ...-exec mv -t . {} + may be slightly faster (less calls on mv) – ilkkachu Apr 11 '17 at 10:59

This works depending on the number of child directories

mv */* .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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