-1

Hopefully, this should be an easy question for the experienced.

I have a list of folders (x1,x2, ..., xn) in a folder called "origin" (i.e. /origin/x1, /origin/x2 etc).

I want to take a particular file (im1.tif in my case) from each folder x1,x2, ..., xn in /origin and copy it to a folder in a destination folder called 'dest', which has the same name (i.e. /dest/x1, /dest/x2 etc).

Could someone help me with this?

Thank you!

0

find + bash solution:

find /origin -type f -name "*.tif" -exec bash -c \
'd="$(dirname $1)"; d=${d##*/}; fn=${1##*/}; 
[ -d "/dest/$d" ] && cp "$1" "/dest/$d/$fn"; ' _ {} \;

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.