Rm command

Removes a “folder” or a set of files matching a pattern. Use with caution.

Note

rm is a high-level command that under the hood utilizes multiple calls to the server, which means the server cannot guarantee consistency between multiple operations. For example if a file matching a pattern is uploaded during a run of rm command, it MIGHT be deleted (as “latest”) instead of the one present when the rm run has started.

In order to safely delete a single file version, please use delete-file-version.

To list (but not remove) files to be deleted, use --dry-run. You can also list files via ls command - the listing behaviour is exactly the same.

Progress is displayed on the console unless --no-progress is specified.

Use –threads to manually adjust the number of threads used in the operation. Otherwise, the number of threads will be automatically chosen.

The --versions option selects all versions of each file, not just the most recent.

The --recursive option will descend into folders, and will select only files, not folders.

The --with-wildcard option will allow using *, ? and `[]` characters in folderName as a greedy wildcard, single character wildcard and range of characters. It requires the --recursive option. Remember to quote folderName to avoid shell expansion.

The –include and –exclude flags can be used to filter the files returned from the server using wildcards. You can specify multiple –include and –exclude filters. The order of filters matters. The last matching filter decides whether a file is included or excluded. If the given list of filters contains only INCLUDE filters, then it is assumed that all files are excluded by default.

The --dry-run option prints all the files that would be affected by the command, but removes nothing.

Normally, when an error happens during file removal, log is printed and the command goes further. If any error should be immediately breaking the command, --fail-fast can be passed to ensure that first error will stop the execution. This could be useful to e.g. check whether provided credentials have deleteFiles capabilities.

Note

Using --fail-fast doesn’t prevent the command from trying to remove further files. It just stops the progress. Since multiple files are removed in parallel, it’s possible that just some of them were not reported.

Command returns 0 if all files were removed successfully and a value different from 0 if any file was left.

Examples.

Note

Note the use of quotes, to ensure that special characters are not expanded by the shell.

Note

Use with caution. Running examples presented below can cause data-loss.

Remove all csv and tsv files (in any directory, in the whole bucket):

b2 rm --recursive --withWildcard bucketName "*.[ct]sv"

Remove all info.txt files from buckets bX, where X is any character:

b2 rm --recursive --withWildcard bucketName "b?/info.txt"

Remove all pdf files from buckets b0 to b9 (including sub-directories):

b2 rm --recursive --withWildcard bucketName "b[0-9]/*.pdf"


Requires capability:

- **listFiles**
- **deleteFiles**

b2 rm [-h] [--dry-run] [--queue-size QUEUE_SIZE] [--no-progress] [--fail-fast]
      [--threads THREADS] [--versions] [-r] [--with-wildcard]
      [--include FILTERS] [--exclude FILTERS]
      bucketName [folderName]

Positional Arguments

bucketName

Target bucket name

folderName

Named Arguments

--dry-run

Default: False

--queue-size

max elements fetched at once for removal, if left unset defaults to twice the number of threads.

--no-progress

Default: False

--fail-fast

Default: False

--threads
--versions

Default: False

-r, --recursive

Default: False

--with-wildcard

Default: False

--include

Default: []

--exclude

Default: []