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

Clash 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
rsync
add a comment |Â
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
rsync
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
add a comment |Â
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
rsync
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
rsync
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
add a comment |Â
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
add a comment |Â
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.
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
add a comment |Â
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.
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered Oct 16 '17 at 19:04
RobertL
4,685523
4,685523
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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