0

I have a filestructure with several subfolders where I'd like to search for all subfolder containing a certain string ("sub*") and then move all of the files in these found folders up one level from each of their respective location. And even potentially delete the then empty folder but I could do that with a second step as well.

1

This should do it:

find /path/to/base/folder/ -type d -name 'sub*' -exec bash -c 'mv {}/* "$(dirname {})"' \;

NOTE: this will not move hidden files (whose name start with .)

  • What is "dirname" in this supposed to be? – Fabian Dec 15 '16 at 12:36
  • 1
    This is the name of a command, see man dirname – NarūnasK Dec 15 '16 at 12:36
  • 1
    Okay, i tried it out. Unfortunately it does not do what I want. it moves the Folder found with "find" up one directory. However what i need is the content IN the folder to be moved up one level (so basically then on the same level as the folder) – Fabian Dec 15 '16 at 12:44
-1
find /path/to -type f -execdir 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.