Can rsync --include match zero-or-one-character?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Can



rsync -a --include="*.[Jj][Pp][Gg]" --include="*.[Jj][Pp][Ee][Gg]" --include="*.[Jj][Ff][Ii][Ff]" --exclude="*" tmp/a/* tmp/b/


be simplified to something like



rsync -a --include="*.[Jj][PpFf][EIi]?[GgFf]" --exclude="*" tmp/a/* tmp/b/


to match .jpg .JFIF .jpeg as does:



ls tmp/a/*.J,jP,p,F,fI,i,E,e,G,g,F,f 2>/dev/null


I created an example test that works, but I'd like to combine the image matching
includes into one --include without the danger of
--include="*.[Jj][Pp]*[Gg]" which matches foo.jp.png (which I don't want to copy.)



mkdir -p tmp/a; touch tmp/a/foo.jpeg; touch tmp/a/bar.jpg; rm tmp/b/*; rsync -a --include="*.[Jj][Pp][Gg]" --include="*.[Jj][Pp][Ee][Gg]" --include="*.[Jj][Ff][Ii][Ff]" --exclude="*" tmp/a/* tmp/b/ ; ls -la tmp/b







share|improve this question




















  • You really shouldn't try to combine two extensions in one. The way you're trying to achieve this, you'd also include files with extensions like jfig, jpig, jpif etc. - You can always try to include the case-insensitive patch to rsync to ease up your line. See this answer here
    – Stefan M
    Oct 16 '17 at 15:03















up vote
0
down vote

favorite












Can



rsync -a --include="*.[Jj][Pp][Gg]" --include="*.[Jj][Pp][Ee][Gg]" --include="*.[Jj][Ff][Ii][Ff]" --exclude="*" tmp/a/* tmp/b/


be simplified to something like



rsync -a --include="*.[Jj][PpFf][EIi]?[GgFf]" --exclude="*" tmp/a/* tmp/b/


to match .jpg .JFIF .jpeg as does:



ls tmp/a/*.J,jP,p,F,fI,i,E,e,G,g,F,f 2>/dev/null


I created an example test that works, but I'd like to combine the image matching
includes into one --include without the danger of
--include="*.[Jj][Pp]*[Gg]" which matches foo.jp.png (which I don't want to copy.)



mkdir -p tmp/a; touch tmp/a/foo.jpeg; touch tmp/a/bar.jpg; rm tmp/b/*; rsync -a --include="*.[Jj][Pp][Gg]" --include="*.[Jj][Pp][Ee][Gg]" --include="*.[Jj][Ff][Ii][Ff]" --exclude="*" tmp/a/* tmp/b/ ; ls -la tmp/b







share|improve this question




















  • You really shouldn't try to combine two extensions in one. The way you're trying to achieve this, you'd also include files with extensions like jfig, jpig, jpif etc. - You can always try to include the case-insensitive patch to rsync to ease up your line. See this answer here
    – Stefan M
    Oct 16 '17 at 15:03













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Can



rsync -a --include="*.[Jj][Pp][Gg]" --include="*.[Jj][Pp][Ee][Gg]" --include="*.[Jj][Ff][Ii][Ff]" --exclude="*" tmp/a/* tmp/b/


be simplified to something like



rsync -a --include="*.[Jj][PpFf][EIi]?[GgFf]" --exclude="*" tmp/a/* tmp/b/


to match .jpg .JFIF .jpeg as does:



ls tmp/a/*.J,jP,p,F,fI,i,E,e,G,g,F,f 2>/dev/null


I created an example test that works, but I'd like to combine the image matching
includes into one --include without the danger of
--include="*.[Jj][Pp]*[Gg]" which matches foo.jp.png (which I don't want to copy.)



mkdir -p tmp/a; touch tmp/a/foo.jpeg; touch tmp/a/bar.jpg; rm tmp/b/*; rsync -a --include="*.[Jj][Pp][Gg]" --include="*.[Jj][Pp][Ee][Gg]" --include="*.[Jj][Ff][Ii][Ff]" --exclude="*" tmp/a/* tmp/b/ ; ls -la tmp/b







share|improve this question












Can



rsync -a --include="*.[Jj][Pp][Gg]" --include="*.[Jj][Pp][Ee][Gg]" --include="*.[Jj][Ff][Ii][Ff]" --exclude="*" tmp/a/* tmp/b/


be simplified to something like



rsync -a --include="*.[Jj][PpFf][EIi]?[GgFf]" --exclude="*" tmp/a/* tmp/b/


to match .jpg .JFIF .jpeg as does:



ls tmp/a/*.J,jP,p,F,fI,i,E,e,G,g,F,f 2>/dev/null


I created an example test that works, but I'd like to combine the image matching
includes into one --include without the danger of
--include="*.[Jj][Pp]*[Gg]" which matches foo.jp.png (which I don't want to copy.)



mkdir -p tmp/a; touch tmp/a/foo.jpeg; touch tmp/a/bar.jpg; rm tmp/b/*; rsync -a --include="*.[Jj][Pp][Gg]" --include="*.[Jj][Pp][Ee][Gg]" --include="*.[Jj][Ff][Ii][Ff]" --exclude="*" tmp/a/* tmp/b/ ; ls -la tmp/b









share|improve this question











share|improve this question




share|improve this question










asked Oct 16 '17 at 14:16









Alexx Roche

22226




22226











  • You really shouldn't try to combine two extensions in one. The way you're trying to achieve this, you'd also include files with extensions like jfig, jpig, jpif etc. - You can always try to include the case-insensitive patch to rsync to ease up your line. See this answer here
    – Stefan M
    Oct 16 '17 at 15:03

















  • You really shouldn't try to combine two extensions in one. The way you're trying to achieve this, you'd also include files with extensions like jfig, jpig, jpif etc. - You can always try to include the case-insensitive patch to rsync to ease up your line. See this answer here
    – Stefan M
    Oct 16 '17 at 15:03
















You really shouldn't try to combine two extensions in one. The way you're trying to achieve this, you'd also include files with extensions like jfig, jpig, jpif etc. - You can always try to include the case-insensitive patch to rsync to ease up your line. See this answer here
– Stefan M
Oct 16 '17 at 15:03





You really shouldn't try to combine two extensions in one. The way you're trying to achieve this, you'd also include files with extensions like jfig, jpig, jpif etc. - You can always try to include the case-insensitive patch to rsync to ease up your line. See this answer here
– Stefan M
Oct 16 '17 at 15:03











2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










You might be better off using a different tool to find the list of files and then piping them into rsync. Eg:



find /tmp/a -iregex '.*(jpe?g|jfif)' | 
rsync -nav --files-from=- / /tmp/b


The -iregex means ignoring case. The regex pattern has an implied ^ at the beginning and $ at the end. The default regex type is emacs, hence the need for backslashes.



(I've left a -n in the rsync to not copy anything).
Beware, using --files-from implies -R, which means the full path, eg tmp/a/t.jpg, will be copied to the destination, which is also why I've used an absolute path in the find, and as the rsync from directory (/). This is just to simplify testing until you understand what starting directory you need to give for the find and the rsync.



For example, to drop the tmp/a prefix you could do (cd /tmp/a; find . ... ) | rsync ... /tmp/a /tmp/b. The find will output t.jpg, and rsync will find that file in /tmp/a, and create file t.jpg in /tmp/b.






share|improve this answer






















  • Thank you. find tmp/a -iregex '.*(jpe?g|jfif)'|sed 's,^tmp/a/,,'|rsync -av --files-from=- ./tmp/a ./tmp/b solved this for me directly from your answer.
    – Alexx Roche
    Oct 17 '17 at 9:46

















up vote
0
down vote













I like @meuh's answer. This answer explains why meuh's answer is the way to do zero or one matching for rsync



I don't believe the zero-or-one feature is available on the rsync command line, according to the INCLUDE/EXCLUDE PATTERN RULES on the rsync man page.



rsync appears to use an expanded version of the shell's command line pattern matching ("globbing"), which is different than regular expression matching.



The zero-or-one feature is available in extended pattern matching of some shells (the extglob option in bash) but I don't see any discussion of this or similar extended pattern matching features on the rsync man page.






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f398427%2fcan-rsync-include-match-zero-or-one-character%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    You might be better off using a different tool to find the list of files and then piping them into rsync. Eg:



    find /tmp/a -iregex '.*(jpe?g|jfif)' | 
    rsync -nav --files-from=- / /tmp/b


    The -iregex means ignoring case. The regex pattern has an implied ^ at the beginning and $ at the end. The default regex type is emacs, hence the need for backslashes.



    (I've left a -n in the rsync to not copy anything).
    Beware, using --files-from implies -R, which means the full path, eg tmp/a/t.jpg, will be copied to the destination, which is also why I've used an absolute path in the find, and as the rsync from directory (/). This is just to simplify testing until you understand what starting directory you need to give for the find and the rsync.



    For example, to drop the tmp/a prefix you could do (cd /tmp/a; find . ... ) | rsync ... /tmp/a /tmp/b. The find will output t.jpg, and rsync will find that file in /tmp/a, and create file t.jpg in /tmp/b.






    share|improve this answer






















    • Thank you. find tmp/a -iregex '.*(jpe?g|jfif)'|sed 's,^tmp/a/,,'|rsync -av --files-from=- ./tmp/a ./tmp/b solved this for me directly from your answer.
      – Alexx Roche
      Oct 17 '17 at 9:46














    up vote
    2
    down vote



    accepted










    You might be better off using a different tool to find the list of files and then piping them into rsync. Eg:



    find /tmp/a -iregex '.*(jpe?g|jfif)' | 
    rsync -nav --files-from=- / /tmp/b


    The -iregex means ignoring case. The regex pattern has an implied ^ at the beginning and $ at the end. The default regex type is emacs, hence the need for backslashes.



    (I've left a -n in the rsync to not copy anything).
    Beware, using --files-from implies -R, which means the full path, eg tmp/a/t.jpg, will be copied to the destination, which is also why I've used an absolute path in the find, and as the rsync from directory (/). This is just to simplify testing until you understand what starting directory you need to give for the find and the rsync.



    For example, to drop the tmp/a prefix you could do (cd /tmp/a; find . ... ) | rsync ... /tmp/a /tmp/b. The find will output t.jpg, and rsync will find that file in /tmp/a, and create file t.jpg in /tmp/b.






    share|improve this answer






















    • Thank you. find tmp/a -iregex '.*(jpe?g|jfif)'|sed 's,^tmp/a/,,'|rsync -av --files-from=- ./tmp/a ./tmp/b solved this for me directly from your answer.
      – Alexx Roche
      Oct 17 '17 at 9:46












    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    You might be better off using a different tool to find the list of files and then piping them into rsync. Eg:



    find /tmp/a -iregex '.*(jpe?g|jfif)' | 
    rsync -nav --files-from=- / /tmp/b


    The -iregex means ignoring case. The regex pattern has an implied ^ at the beginning and $ at the end. The default regex type is emacs, hence the need for backslashes.



    (I've left a -n in the rsync to not copy anything).
    Beware, using --files-from implies -R, which means the full path, eg tmp/a/t.jpg, will be copied to the destination, which is also why I've used an absolute path in the find, and as the rsync from directory (/). This is just to simplify testing until you understand what starting directory you need to give for the find and the rsync.



    For example, to drop the tmp/a prefix you could do (cd /tmp/a; find . ... ) | rsync ... /tmp/a /tmp/b. The find will output t.jpg, and rsync will find that file in /tmp/a, and create file t.jpg in /tmp/b.






    share|improve this answer














    You might be better off using a different tool to find the list of files and then piping them into rsync. Eg:



    find /tmp/a -iregex '.*(jpe?g|jfif)' | 
    rsync -nav --files-from=- / /tmp/b


    The -iregex means ignoring case. The regex pattern has an implied ^ at the beginning and $ at the end. The default regex type is emacs, hence the need for backslashes.



    (I've left a -n in the rsync to not copy anything).
    Beware, using --files-from implies -R, which means the full path, eg tmp/a/t.jpg, will be copied to the destination, which is also why I've used an absolute path in the find, and as the rsync from directory (/). This is just to simplify testing until you understand what starting directory you need to give for the find and the rsync.



    For example, to drop the tmp/a prefix you could do (cd /tmp/a; find . ... ) | rsync ... /tmp/a /tmp/b. The find will output t.jpg, and rsync will find that file in /tmp/a, and create file t.jpg in /tmp/b.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Oct 16 '17 at 18:48

























    answered Oct 16 '17 at 18:36









    meuh

    29.8k11751




    29.8k11751











    • Thank you. find tmp/a -iregex '.*(jpe?g|jfif)'|sed 's,^tmp/a/,,'|rsync -av --files-from=- ./tmp/a ./tmp/b solved this for me directly from your answer.
      – Alexx Roche
      Oct 17 '17 at 9:46
















    • Thank you. find tmp/a -iregex '.*(jpe?g|jfif)'|sed 's,^tmp/a/,,'|rsync -av --files-from=- ./tmp/a ./tmp/b solved this for me directly from your answer.
      – Alexx Roche
      Oct 17 '17 at 9:46















    Thank you. find tmp/a -iregex '.*(jpe?g|jfif)'|sed 's,^tmp/a/,,'|rsync -av --files-from=- ./tmp/a ./tmp/b solved this for me directly from your answer.
    – Alexx Roche
    Oct 17 '17 at 9:46




    Thank you. find tmp/a -iregex '.*(jpe?g|jfif)'|sed 's,^tmp/a/,,'|rsync -av --files-from=- ./tmp/a ./tmp/b solved this for me directly from your answer.
    – Alexx Roche
    Oct 17 '17 at 9:46












    up vote
    0
    down vote













    I like @meuh's answer. This answer explains why meuh's answer is the way to do zero or one matching for rsync



    I don't believe the zero-or-one feature is available on the rsync command line, according to the INCLUDE/EXCLUDE PATTERN RULES on the rsync man page.



    rsync appears to use an expanded version of the shell's command line pattern matching ("globbing"), which is different than regular expression matching.



    The zero-or-one feature is available in extended pattern matching of some shells (the extglob option in bash) but I don't see any discussion of this or similar extended pattern matching features on the rsync man page.






    share|improve this answer
























      up vote
      0
      down vote













      I like @meuh's answer. This answer explains why meuh's answer is the way to do zero or one matching for rsync



      I don't believe the zero-or-one feature is available on the rsync command line, according to the INCLUDE/EXCLUDE PATTERN RULES on the rsync man page.



      rsync appears to use an expanded version of the shell's command line pattern matching ("globbing"), which is different than regular expression matching.



      The zero-or-one feature is available in extended pattern matching of some shells (the extglob option in bash) but I don't see any discussion of this or similar extended pattern matching features on the rsync man page.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        I like @meuh's answer. This answer explains why meuh's answer is the way to do zero or one matching for rsync



        I don't believe the zero-or-one feature is available on the rsync command line, according to the INCLUDE/EXCLUDE PATTERN RULES on the rsync man page.



        rsync appears to use an expanded version of the shell's command line pattern matching ("globbing"), which is different than regular expression matching.



        The zero-or-one feature is available in extended pattern matching of some shells (the extglob option in bash) but I don't see any discussion of this or similar extended pattern matching features on the rsync man page.






        share|improve this answer












        I like @meuh's answer. This answer explains why meuh's answer is the way to do zero or one matching for rsync



        I don't believe the zero-or-one feature is available on the rsync command line, according to the INCLUDE/EXCLUDE PATTERN RULES on the rsync man page.



        rsync appears to use an expanded version of the shell's command line pattern matching ("globbing"), which is different than regular expression matching.



        The zero-or-one feature is available in extended pattern matching of some shells (the extglob option in bash) but I don't see any discussion of this or similar extended pattern matching features on the rsync man page.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 16 '17 at 19:04









        RobertL

        4,685523




        4,685523



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f398427%2fcan-rsync-include-match-zero-or-one-character%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)