Skip to content

Instantly share code, notes, and snippets.

@aessing
Created October 1, 2020 19:50
Show Gist options
  • Save aessing/76f1200c9f5b2b9671937b3b0ed5fd6f to your computer and use it in GitHub Desktop.
Save aessing/76f1200c9f5b2b9671937b3b0ed5fd6f to your computer and use it in GitHub Desktop.
Install AzCopy on Linux
#!/bin/bash
# =============================================================================
# Install AzCopy on Linux
# https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10
# https://github.com/Azure/azure-storage-azcopy
# -----------------------------------------------------------------------------
# Developer.......: Andre Essing (https://www.andre-essing.de/)
# (https://github.com/aessing)
# (https://twitter.com/aessing)
# (https://www.linkedin.com/in/aessing/)
# -----------------------------------------------------------------------------
# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
# =============================================================================
# Download and extract
wget https://aka.ms/downloadazcopy-v10-linux
tar -xvf downloadazcopy-v10-linux
# Move AzCopy
sudo rm -f /usr/bin/azcopy
sudo cp ./azcopy_linux_amd64_*/azcopy /usr/bin/
sudo chmod 755 /usr/bin/azcopy
# Clean the kitchen
rm -f downloadazcopy-v10-linux
rm -rf ./azcopy_linux_amd64_*/
@spoelstraethan
Copy link

You could make this a one-liner (three commands) with sudo bash -c 'cd /usr/local/bin; curl -L https://aka.ms/downloadazcopy-v10-linux | tar --strip-components=1 --exclude=*.txt -xzvf -; chmod +x azcopy' and not have to deal with cleaning up any local files. If you don't want any user other than root to execute it, just do u+x for the chmod.

@aessing
Copy link
Author

aessing commented Jan 23, 2023

You could make this a one-liner (three commands) with sudo bash -c 'cd /usr/local/bin; curl -L https://aka.ms/downloadazcopy-v10-linux | tar --strip-components=1 --exclude=*.txt -xzvf -; chmod +x azcopy' and not have to deal with cleaning up any local files. If you don't want any user other than root to execute it, just do u+x for the chmod.

Thanks @spoelstraethan, thats true, you can reduce this to just one line.
Reducing it to a single line is cool for copy and paste and when you want to run it manually on CLI.

In scripts, like the one above, I like to have separate commands to make it more readable and understandable. Makes it easier for newbies. Also for small tasks like this I don't care for a few more IOPS and a 1 or 2 second longer runtime.

But, thanks for the great sample.

@hvitis
Copy link

hvitis commented Oct 31, 2023

sudo bash -c 'cd /usr/local/bin; curl -L https://aka.ms/downloadazcopy-v10-linux | tar --strip-components=1 --exclude=*.txt -xzvf -; chmod +x azcopy'

Genius

sudo bash -c 'cd /usr/local/bin; curl -L https://aka.ms/downloadazcopy-v10-linux | tar --strip-components=1 --exclude=*.txt -xzvf -; chmod +x azcopy'

@orgads
Copy link

orgads commented Nov 23, 2023

Slightly improved version (without forking a shell):

curl -L https://aka.ms/downloadazcopy-v10-linux | sudo tar --strip-components=1 -C /usr/local/bin --no-same-owner --exclude=*.txt -xzvf -

@aessing
Copy link
Author

aessing commented Nov 24, 2023

Slightly improved version (without forking a shell):

curl -L https://aka.ms/downloadazcopy-v10-linux | sudo tar --strip-components=1 -C /usr/local/bin --no-same-owner --exclude=*.txt -xzvf -

Awesome @orgads, Thank you!

@sambar1729
Copy link

I agree with @aessing (thanks Andre!) for the script. Keeping the gist as separate lines is good for readability. People who want the oneliners can use those, but good that the gist is in separate lines.

@rzewus
Copy link

rzewus commented Jan 28, 2024

curl -L https://aka.ms/downloadazcopy-v10-linux | sudo tar --strip-components=1 -C /usr/local/bin --no-same-owner --exclude=*.txt -xzvf -| sudo chmod 755 /usr/local/bin/azcopy
aaand the final chmod to actually use this as non root ;)

@SolomidHero
Copy link

Use quotes on "*.txt" to run it inside zsh

curl -L https://aka.ms/downloadazcopy-v10-linux | sudo tar --strip-components=1 -C /usr/local/bin --no-same-owner --exclude="*.txt" -xzvf - | sudo chmod 755 /usr/local/bin/azcopy

@aessing
Copy link
Author

aessing commented May 3, 2024

Thanks @rzewus and thanks @SolomidHero for your suggestions and help getting my code into a one-liner.
Love it

@d-mankowski-synerise
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment