I am trying to move content of a subfolder to it's parent folder and delete the now empty subfolder. I want this to happen to multiple parent folders each with their own unique client name. I've taken a screenshot of the folder hierarchy which can be viewed here >>> http://i.imgur.com/LSjjx4K.png

Each CLIENT folder has a subfolder labeled '#msgs' with content that needs to be moved up one folder. I was doing this in awkward 3 step fashion written out below:

cd /Users/SystemFive/Desktop/ROOT/PARENT\ DIRECTORY/CLIENT\ 1
mv \#msgs/* .


find . -type d -name "#msgs" -exec rm -fvr "{}" \;

This is pretty cumbersome for my project as I have over a hundred client folders I need to do this for. I am looking for direction to create some sort of if/then statement that can run through the entire PARENT DIRECTORY through each of the CLIENT folders and perform this action. Any help is appreciated. Thank you!

Screenshot of Folder Structure

find . -iname '#msgs' | perl -pe 's/(.*)(#msgs)/mv "$1$2\/*" "$1";\nrm -r "$1$2";/g' | bash

omit the | bash to see what it would do

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.