file - Centos: Merge directories while removing a common subdirectory in all subs -


very weird , specific question know save me big headache.

is possible merge directories while removing specific sub in each sub keeping files? example

i have

/first/1/files/1.jpg, 2.jpg, 3.jpg /first/2/files/1.jpg, 2.jpg, 3.jpg 

i have

/second/1/3.jpg, 4.jpg, 5.jpg /second/2/3.jpg, 4.jpg, 5.jpg 

i want merge /first /second while removing inbetween /files/ directory in /first keeping jpgs. on top of that, don't want 3.jpg overwritten in /second/

if timestamps don't matter like:

find /second -name '*.jpg' -exec touch + fdir in /first/*/files;     sdir=${fdir%/files};     sdir=${sdir#/tmp/first};     sdir=/tmp/second${sdir};     cp -u "$fdir/"* "$sdir/"; done 

though that's not i'd call solution.

you manually testing existing files while looping , copying this:

for ffile in /first/*/files/*.jpg;     # expand variable , delete '/files'     sfile=${ffile/\/files}     # expand variable , remove '/first' prefix     sfile=${sfile#/tmp/first}     # prepend new '/second' direcory.     sfile=/second${sfile}     # if exist nothing. if doesn't copy.     [ -f "$sfile" ] || cp -u "$ffile" "$sfile" done 

i feel there clever way rsync or cpio don't know is.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -