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 >>> https://i.stack.imgur.com/Ve4Cj.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

1 Answer 1

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

You must log in to answer this question.

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