aws cli s3 sync: how to exclude multiple files2019 Community Moderator ElectionHow do I parse command line arguments in Bash?How to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How can I exclude all “permission denied” messages from “find”?How can I redirect and append both stdout and stderr to a file with Bash?How do I split a string on a delimiter in Bash?How to count all the lines of code in a directory recursively?How do I reload .bashrc without logging out and back in?How to concatenate string variables in Bash
Are all passive ability checks floors for active ability checks?
What are substitutions for coconut in curry?
how to write formula in word in latex
Did Ender ever learn that he killed Stilson and/or Bonzo?
How to make healing in an exploration game interesting
Are ETF trackers fundamentally better than individual stocks?
Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?
What is the significance behind "40 days" that often appears in the Bible?
How to write cleanly even if my character uses expletive language?
How do I hide Chekhov's Gun?
Does Mathematica reuse previous computations?
Life insurance that covers only simultaneous/dual deaths
Unexpected result from ArcLength
Is it possible to upcast ritual spells?
Why do Australian milk farmers need to protest supermarkets' milk price?
Why is the President allowed to veto a cancellation of emergency powers?
Look at your watch and tell me what time is it. vs Look at your watch and tell me what time it is
A link redirect to http instead of https: how critical is it?
Python if-else code style for reduced code for rounding floats
How to terminate ping <dest> &
Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible
Min function accepting varying number of arguments in C++17
Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?
Why doesn't the EU now just force the UK to choose between referendum and no-deal?
aws cli s3 sync: how to exclude multiple files
2019 Community Moderator ElectionHow do I parse command line arguments in Bash?How to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How can I exclude all “permission denied” messages from “find”?How can I redirect and append both stdout and stderr to a file with Bash?How do I split a string on a delimiter in Bash?How to count all the lines of code in a directory recursively?How do I reload .bashrc without logging out and back in?How to concatenate string variables in Bash
So I have a bash script which deletes all contents from an AWS S3 bucket and then uploads the contents of a local folder to that same bucket.
#!/bin/bash
# deploy to s3
function deploy()
aws s3 rm s3://bucketname --profile Administrator --recursive
aws s3 sync ./ s3://bucketname --profile Administrator --exclude='node_modules/*' --exclude='.git/*' --exclude='clickCounter.py' --exclude='package-lock.json' --exclude='bundle.js.map' --exclude='package.json' --exclude='webpack_dev_server.js' --exclude='.vscode/*' --exclude='.DS_Store'
deploy
However - as you can see, I have quite a few files to be excluded, and this list may increase in the future.
So my question: Is there a way I can just put the files to be excluded into an array and then iterate over that?
Perhaps something like:
#!/bin/bash
arrayOfExcludedItems = (node_modules/* package-lock.json bundle.js.map )
# deploy to s3
function deploy()
aws s3 rm s3://bucketname --profile Administrator --recursive
aws s3 sync ./ s3://bucketname --profile Administrator for item in arrayOfExcludedItems --exclude
deploy
bash amazon-s3 aws-cli
add a comment |
So I have a bash script which deletes all contents from an AWS S3 bucket and then uploads the contents of a local folder to that same bucket.
#!/bin/bash
# deploy to s3
function deploy()
aws s3 rm s3://bucketname --profile Administrator --recursive
aws s3 sync ./ s3://bucketname --profile Administrator --exclude='node_modules/*' --exclude='.git/*' --exclude='clickCounter.py' --exclude='package-lock.json' --exclude='bundle.js.map' --exclude='package.json' --exclude='webpack_dev_server.js' --exclude='.vscode/*' --exclude='.DS_Store'
deploy
However - as you can see, I have quite a few files to be excluded, and this list may increase in the future.
So my question: Is there a way I can just put the files to be excluded into an array and then iterate over that?
Perhaps something like:
#!/bin/bash
arrayOfExcludedItems = (node_modules/* package-lock.json bundle.js.map )
# deploy to s3
function deploy()
aws s3 rm s3://bucketname --profile Administrator --recursive
aws s3 sync ./ s3://bucketname --profile Administrator for item in arrayOfExcludedItems --exclude
deploy
bash amazon-s3 aws-cli
add a comment |
So I have a bash script which deletes all contents from an AWS S3 bucket and then uploads the contents of a local folder to that same bucket.
#!/bin/bash
# deploy to s3
function deploy()
aws s3 rm s3://bucketname --profile Administrator --recursive
aws s3 sync ./ s3://bucketname --profile Administrator --exclude='node_modules/*' --exclude='.git/*' --exclude='clickCounter.py' --exclude='package-lock.json' --exclude='bundle.js.map' --exclude='package.json' --exclude='webpack_dev_server.js' --exclude='.vscode/*' --exclude='.DS_Store'
deploy
However - as you can see, I have quite a few files to be excluded, and this list may increase in the future.
So my question: Is there a way I can just put the files to be excluded into an array and then iterate over that?
Perhaps something like:
#!/bin/bash
arrayOfExcludedItems = (node_modules/* package-lock.json bundle.js.map )
# deploy to s3
function deploy()
aws s3 rm s3://bucketname --profile Administrator --recursive
aws s3 sync ./ s3://bucketname --profile Administrator for item in arrayOfExcludedItems --exclude
deploy
bash amazon-s3 aws-cli
So I have a bash script which deletes all contents from an AWS S3 bucket and then uploads the contents of a local folder to that same bucket.
#!/bin/bash
# deploy to s3
function deploy()
aws s3 rm s3://bucketname --profile Administrator --recursive
aws s3 sync ./ s3://bucketname --profile Administrator --exclude='node_modules/*' --exclude='.git/*' --exclude='clickCounter.py' --exclude='package-lock.json' --exclude='bundle.js.map' --exclude='package.json' --exclude='webpack_dev_server.js' --exclude='.vscode/*' --exclude='.DS_Store'
deploy
However - as you can see, I have quite a few files to be excluded, and this list may increase in the future.
So my question: Is there a way I can just put the files to be excluded into an array and then iterate over that?
Perhaps something like:
#!/bin/bash
arrayOfExcludedItems = (node_modules/* package-lock.json bundle.js.map )
# deploy to s3
function deploy()
aws s3 rm s3://bucketname --profile Administrator --recursive
aws s3 sync ./ s3://bucketname --profile Administrator for item in arrayOfExcludedItems --exclude
deploy
bash amazon-s3 aws-cli
bash amazon-s3 aws-cli
edited Mar 7 at 14:11
Filtenborg
asked Mar 7 at 13:52
FiltenborgFiltenborg
14239
14239
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can't use a loop in the middle of an argument list, but you can do a textual substitution adding "--exclude=" to the beginning of each element. First, though, you must declare the array correctly; that means no spaces around the =
, and you need to quote any entries that contain wildcards (that you don't want expanded on the spot):
arrayOfExcludedItems=('node_modules/*' '.git/*' clickCounter.py package-lock.json
bundle.js.map package.json webpack_dev_server.js '.vscode/*' .DS_Store)
Then use the array like this:
aws s3 sync ./ s3://bucketname --profile Administrator
"$arrayOfExcludedItems[@]/#/--exclude="
How it works: the [@]
tells the shell to get all elements of the array (treating each as a separate word), the /#a/b
part tells it to replace a
at the beginning of each element with b
, but a
is empty so it effectively just adds "--exclude=" to the beginning. Oh, and the double-quotes around it tells the shell not to expand wildcards or otherwise mess with the results.
Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir
– Filtenborg
Mar 7 at 21:26
The /#a/b is very cool. I had no idea you could use it to transform an array.
– Alex Harvey
Mar 8 at 8:41
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55045423%2faws-cli-s3-sync-how-to-exclude-multiple-files%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't use a loop in the middle of an argument list, but you can do a textual substitution adding "--exclude=" to the beginning of each element. First, though, you must declare the array correctly; that means no spaces around the =
, and you need to quote any entries that contain wildcards (that you don't want expanded on the spot):
arrayOfExcludedItems=('node_modules/*' '.git/*' clickCounter.py package-lock.json
bundle.js.map package.json webpack_dev_server.js '.vscode/*' .DS_Store)
Then use the array like this:
aws s3 sync ./ s3://bucketname --profile Administrator
"$arrayOfExcludedItems[@]/#/--exclude="
How it works: the [@]
tells the shell to get all elements of the array (treating each as a separate word), the /#a/b
part tells it to replace a
at the beginning of each element with b
, but a
is empty so it effectively just adds "--exclude=" to the beginning. Oh, and the double-quotes around it tells the shell not to expand wildcards or otherwise mess with the results.
Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir
– Filtenborg
Mar 7 at 21:26
The /#a/b is very cool. I had no idea you could use it to transform an array.
– Alex Harvey
Mar 8 at 8:41
add a comment |
You can't use a loop in the middle of an argument list, but you can do a textual substitution adding "--exclude=" to the beginning of each element. First, though, you must declare the array correctly; that means no spaces around the =
, and you need to quote any entries that contain wildcards (that you don't want expanded on the spot):
arrayOfExcludedItems=('node_modules/*' '.git/*' clickCounter.py package-lock.json
bundle.js.map package.json webpack_dev_server.js '.vscode/*' .DS_Store)
Then use the array like this:
aws s3 sync ./ s3://bucketname --profile Administrator
"$arrayOfExcludedItems[@]/#/--exclude="
How it works: the [@]
tells the shell to get all elements of the array (treating each as a separate word), the /#a/b
part tells it to replace a
at the beginning of each element with b
, but a
is empty so it effectively just adds "--exclude=" to the beginning. Oh, and the double-quotes around it tells the shell not to expand wildcards or otherwise mess with the results.
Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir
– Filtenborg
Mar 7 at 21:26
The /#a/b is very cool. I had no idea you could use it to transform an array.
– Alex Harvey
Mar 8 at 8:41
add a comment |
You can't use a loop in the middle of an argument list, but you can do a textual substitution adding "--exclude=" to the beginning of each element. First, though, you must declare the array correctly; that means no spaces around the =
, and you need to quote any entries that contain wildcards (that you don't want expanded on the spot):
arrayOfExcludedItems=('node_modules/*' '.git/*' clickCounter.py package-lock.json
bundle.js.map package.json webpack_dev_server.js '.vscode/*' .DS_Store)
Then use the array like this:
aws s3 sync ./ s3://bucketname --profile Administrator
"$arrayOfExcludedItems[@]/#/--exclude="
How it works: the [@]
tells the shell to get all elements of the array (treating each as a separate word), the /#a/b
part tells it to replace a
at the beginning of each element with b
, but a
is empty so it effectively just adds "--exclude=" to the beginning. Oh, and the double-quotes around it tells the shell not to expand wildcards or otherwise mess with the results.
You can't use a loop in the middle of an argument list, but you can do a textual substitution adding "--exclude=" to the beginning of each element. First, though, you must declare the array correctly; that means no spaces around the =
, and you need to quote any entries that contain wildcards (that you don't want expanded on the spot):
arrayOfExcludedItems=('node_modules/*' '.git/*' clickCounter.py package-lock.json
bundle.js.map package.json webpack_dev_server.js '.vscode/*' .DS_Store)
Then use the array like this:
aws s3 sync ./ s3://bucketname --profile Administrator
"$arrayOfExcludedItems[@]/#/--exclude="
How it works: the [@]
tells the shell to get all elements of the array (treating each as a separate word), the /#a/b
part tells it to replace a
at the beginning of each element with b
, but a
is empty so it effectively just adds "--exclude=" to the beginning. Oh, and the double-quotes around it tells the shell not to expand wildcards or otherwise mess with the results.
edited Mar 11 at 2:42
Alex Harvey
5,2661923
5,2661923
answered Mar 7 at 15:23
Gordon DavissonGordon Davisson
70.3k97894
70.3k97894
Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir
– Filtenborg
Mar 7 at 21:26
The /#a/b is very cool. I had no idea you could use it to transform an array.
– Alex Harvey
Mar 8 at 8:41
add a comment |
Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir
– Filtenborg
Mar 7 at 21:26
The /#a/b is very cool. I had no idea you could use it to transform an array.
– Alex Harvey
Mar 8 at 8:41
Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir
– Filtenborg
Mar 7 at 21:26
Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir
– Filtenborg
Mar 7 at 21:26
The /#a/b is very cool. I had no idea you could use it to transform an array.
– Alex Harvey
Mar 8 at 8:41
The /#a/b is very cool. I had no idea you could use it to transform an array.
– Alex Harvey
Mar 8 at 8:41
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55045423%2faws-cli-s3-sync-how-to-exclude-multiple-files%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown