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.

2 Answers 2

2

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 .)

3
  • What is "dirname" in this supposed to be?
    – Fabian
    Dec 15, 2016 at 12:36
  • 1
    This is the name of a command, see man dirname
    – NarūnasK
    Dec 15, 2016 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, 2016 at 12:44
2
find /path/to -type f -execdir mv {} .. \;
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .