I have Original Source and Backup destination. Inside Original folder I have a lot of files types. I only need JPG, LOG and TXT. I already did the Directory Structure Copy with this command:

cd /var/Sys012/Logs && find . -type d -exec mkdir -p -- /home/re-born/Backup/Logs/{} \;`

How to find *.TXT, *.LOG and *.JPG and move into respective Backup Folder?

Thanks in advance


1 Answer 1


Use rsync:

rsync -av -m \
  --include="*/" \
  --include="*.jpg" \
  --include="*.log" \
  --include="*.txt" \
  --exclude="*" \
"/var/Sys012/Logs" "/home/re-born/Backup/"

-m lets rsync avoid to create empty folders. Omit this option if you don't want this.

This will also create the directory structure for you. To include the extensions independent from case, you might need --include="*.[jJ][pP][gG]".

  • Thank you pLumo, I made a mistake formulating the question, the problem here is the mandatory file is the JPG for example, I have 300.JPG and need to copy 300.log and 300.txt, next I have 301.M4V and 301.TXT and 301.LOG, those files I wont be copied, lets say I need to copy the *.jpg but there childs are *.txt and *.log avoid to copy the *.txt and *.log from other extensions like m4v, png and so... thanks in advance Commented Mar 26, 2020 at 17:54

You must log in to answer this question.

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