I have a directory structure produced during archiving. The archiving system can't be changed. Whenever a duplicate directory occurs the archiver appends an integer suffix to the directory name. My goal is to collapse these so that there is only one directory per name (no suffixes) and sub-directories are merged.
# Current Structure / +-- Folder_Name/ +-- 20170913/ +-- File One +-- Folder_Name_1/ +-- 20170913/ +-- File One +-- File Two +-- Folder_Name_2/ +-- 20170915/ +-- File Three +-- Folder_Name_3/ +-- 20170918/ +-- File Four # What I would like to achieve / +-- Folder_Name/ +-- 20170913/ +-- File One +-- File Two +-- 20170915/ +-- File Three +-- 20170918/ +-- File Four
Lots of folders are created during archiving (it is an ultrasound machine saving a monthly backup of all images) and there are often duplicates produced. At the same time I am using ImageMagick to convert the bitmap files to png in order to keep file sizes down.
I have tried to do this with
rsync using the --remove-source-files option, but I haven't been able to find a way to match these directories for
rsync (I don't think it supports regex). I then tried to use
find to pipe the output into
rsync but can't work out a) the regex that would achieve that; and b) how to provide the suffixed and un-suffixed directory names. I am thinking I need to use variables for this, but am not experienced with shell scripting.
Am I taking the right approach here? If so, could someone point me to a resource or tutorial that can walk me through setting this up? If not then what tools should I be looking at using?