Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (12.9k points)

aws s3 cp "dist/myfile" "s3://my-bucket/production/myfile"

It always copies myfile to s3 - I would like to copy file ONLY if it does no exist, throw error otherwise. How I can do it? Or at least how I can use awscli to check if file exists?

1 Answer

0 votes
by (18.2k points)

You can use the following command to check if a file exists or not:

aws s3 ls s3://bucket/file_name.txt | wc -l

If this command returns nothing that means the file that you searched for does not exist.

Use the following command to copy a file if it does not exist:

aws s3 sync . s3://bucket/ --exclude '*' --include 'file_name.txt'

Learn more about AWS by going through AWS course and master this trending technology.

Related questions

0 votes
2 answers

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

Browse Categories

...