Search code examples
bashfiledirectorymove

Recursively move all files in folders with given name to their parent directory


I have a document library where all of my files are in folder based on category name but then they are also all in subfolders called 'pdf' as well. Is there a way in bash to scan through all of the directories in the library and move all files in folders named pdf to their parent directory?


Solution

  • This can be done with a find command.

    Assuming you have no other folders named pdf, you could run something like this:

    cd path_to_library
    find . -type d -name pdf -exec bash -c 'cd {}; mv * ..' ';'