Linux

Copy recursively files of one type

I needed to copy a bunch of JPGs from one folder structure to a mirror structure, but didn’t want to copy all the RAW files. Came across two examples. I tried the second (mainly because I understand it), and it worked nicely.

Example 1

Code:
#!/bin/bash
cd /home/images
find . -depth -type f -name '*.jpg' | cpio --pass-through \
 --preserve-modification-time \
 --make-directories --verbose /home/new_dir

Example 2

Code:
#!/bin/bash
cd /home/images
find . -type d -name '*' -exec mkdir -p /home/new_dir/{} \;
find . -type f -name '*.jpg' -exec cp {} /home/new_dir/{} \;

 

Leave a Reply

Your email address will not be published. Required fields are marked *