Get the Command-Line Tool
Now that you have created an account, you're ready to get the command-line tool that gives easy access to all of the capabilities of B2 Cloud Storage.
The B2 command-line tool is available in three flavors. We offer an easy-to-use self-contained download, a Python version from the Python Package Index (PyPI), or Github sources.
Self-contained Download
The self-contained download is the easiest way to get up and running, no installation or Python needed. Simply download the version for your operating system and run it from a command window. For detailed documentation, visit our B2 CLI page.
Once you've downloaded the self-contained tool, you can jump right into
how to use the B2 command-line tool in the usage section below.
Prior to running the tool, execute the following command: chmod +x <tool filename>
Python Version
If you'd like to run the Python version of the B2 command-line tool,
it has been packaged in Python modules and published on the Python
Package Index (PyPI). The easiest way to get the Python
version of the B2 command-line Tool is using the standard Python pip
installation tool.
Your first step is to make sure that you have Python 3 (3.5 or later) installed.
Python Installation on Mac (OSX)
To install Python3, pip
, and the B2 command-line tool on Mac OSX:
- Go to Python Releases for Mac OS X, select the "Latest Python 3 Release", and scroll to the bottom.
- Download and run the "macOS 64-bit installer"
-
Open a new Terminal window and type
pip install --upgrade b2
If you see a message like this, it's because Apple installs a really old version of one of the Python libraries that B2 uses:
-
OSError: [Errno 1] Operation not permitted: '/tmp/pip-BMa2Su-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
You can work around this with the --ignore-installed option
:
-
sudo pip install --upgrade --ignore-installed b2
Python Installation on Windows
To install Python3, pip
, and the B2 command-line tool on Windows:
- Go to Python Releases for Windows, select the "Latest Python 3 Release", and scroll to the bottom.
- Download the "Windows x86-64 executable installer". For older 32-bit windows, download the "Windows x86 executable installer".
- Run the installer. By default it will install Python to your Users directory.
- Check the "Add Python 3.x to PATH" box to enable you to use Python from any directory.
-
Open a Command Prompt window and type
pip install --upgrade b2
Github Sources
This version of the B2 command-line tool is useful for Python developers who wish to work with the B2 command-line tool source code. The sources for the B2 Command Line Tool are available from Github in the B2_Command_Line_Tool project.
The first step is make sure that you have Python3 installed and then download the latest version of the source code from Github:
-
git clone https://github.com/Backblaze/B2_Command_Line_Tool.git
The Developer Info section of the project's README.md file has all the info needed to build and contribute to the project.
Usage
Once you have the b2
command-line tool installed, you can type
"b2" on the command-line to see all of the options.
If you see a message like b2: Permission denied
on OSX or Linux, it's because
we need to set the executable bit on the file with the command:
chmod +x b2
This program provides command-line access to the B2 service. Usages: b2 authorize-account [<applicationKeyId>] [<applicationKey>] b2 cancel-all-unfinished-large-files <bucketName> b2 cancel-large-file <fileId> b2 clear-account b2 copy-file-by-id [--metadataDirective [copy|replace]] [--contentType <contentType>] \ [--info <key>=<value>]* [--range start,end] \ <sourceFileId> <destinationBucketName> <b2FileName> b2 create-bucket [--bucketInfo <json>] [--corsRules <json>] [--lifecycleRules <json>] <bucketName> [allPublic | allPrivate] b2 create-key [--duration <validDurationSeconds>] [--bucket <bucketName>] [--namePrefix <namePrefix>] <keyName> <capabilities> b2 delete-bucket <bucketName> b2 delete-file-version [<fileName>] <fileId> b2 delete-key <applicationKeyId> b2 download-file-by-id [--noProgress] <fileId> <localFileName> b2 download-file-by-name [--noProgress] <bucketName> <fileName> <localFileName> b2 get-account-info b2 get-bucket [--showSize] <bucketName> b2 get-download-auth [--prefix <fileNamePrefix>] [--duration <durationInSeconds>] <bucketName> b2 get-download-url-with-auth [--duration <durationInSeconds>] <bucketName> <fileName> b2 get-file-info <fileId> b2 help [commandName] b2 hide-file <bucketName> <fileName> b2 list-buckets b2 list-keys b2 list-parts <largeFileId> b2 list-unfinished-large-files <bucketName> b2 ls [--long] [--versions] [--recursive] <bucketName> [<folderName>] b2 make-url <fileId> b2 sync [--delete] [--keepDays N] [--skipNewer] [--replaceNewer] \ [--compareVersions <option>] [--compareThreshold N] \ [--threads N] [--noProgress] [--dryRun ] [--allowEmptySource ] \ [--excludeRegex <regex> [--includeRegex <regex>]] \ [--excludeDirRegex <regex>] \ [--excludeAllSymlinks ] \ <source> <destination> b2 update-bucket [--bucketInfo <json>] [--corsRules <json>] [--lifecycleRules <json>] <bucketName> [allPublic | allPrivate] b2 upload-file [--sha1 <sha1sum>] [--contentType <contentType>] \ [--info <key>=<value>]* [--minPartSize N] \ [--noProgress] [--threads N] <bucketName> <localFilePath> <b2FileName> b2 version The environment variable B2_ACCOUNT_INFO specifies the sqlite file to use for caching authentication information. The default file to use is: ~/.b2_account_info For more details on one command: b2 help <command> When authorizing with application keys, this tool requires that the key have the 'listBuckets' capability so that it can take the bucket names you provide on the command line and translate them into bucket IDs for the B2 Storage service. Each different command may required additional capabilities. You can find the details for each command in the help for that command.
Now that you have the command-line tool, you're ready to make a bucket to hold your files.