1

Let's say I have a path like this

/x/xx/file

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.

1

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 work just nice. Thanks so much! I would never be able to discover this by myself. – Freedo Apr 13 '17 at 3:57

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.