Introduction

If you’ve ever needed to use regex to find specific files in a directory then you’ll know how useful it is and how much time it saves. This is for when you need to then rsync those files to another location.

Note that this command comes in very handy when you get the dreaded “Argument list too long” error.

Solution

The command structure is as follows:

find . -name "whatever.*" -print0 | rsync -avP --files-from=- --from0 ./ ./destination/

Of course with any solution like this, key is testing on non production system first to ensure what you are doing is going to work. Start by ensuring the regex you are using will find the files needed. Count the files with wc -l to ensure you have the correct number. Then test the rsync portion will copy the intended files to the destination folder.

Source:

http://www.commandlinefu.com/commands/view/7685/rsync-directory-tree-including-only-files-that-match-a-certain-find-result.

 

rsync directory tree including only files that match a certain find result
Tagged on:         

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.

Optimization WordPress Plugins & Solutions by W3 EDGE