This topic describes how to run the hash command to calculate the MD5 hash or the CRC-64 value of a local file.
Usage notes
To calculate the hash of a local file, you must have the
oss:GetObject
permission. For more information, see Attach a custom policy to a RAM user.By default, the object hash calculated by the server is used, which is the CRC-64 value or the Content-MD5 value obtained by calling the headobject operation. If the hash does not exist, download the object and calculate the hash.
Command syntax
ossutil hash md5|crc64 source [flags]
Parameter | Type | Description |
--base64 | / | Specifies whether base64-encode the object hash. |
-d, --dirs | / | Specifies that the objects and subdirectories in the current directory are returned. |
--download | / | Specifies whether to download the object for hash calculation. |
--encoding-type | string | The encoding method used to encode the destination object name. Valid value: url. |
--end-with | string | Specifies that objects whose names are alphabetically before or the same as the value of the --end-with parameter are returned. |
--exclude | stringArray | The exclusion rule for the path or object name. |
--exclude-from | stringArray | Specifies that the exclusion rule is read from the rules file. |
--files-from | stringArray | Specifies that the object names are read from the rules file, and empty lines or comment lines are ignored. |
--files-from-raw | stringArray | Specifies that the object names are read from the rules file. |
--filter | stringArray | The filter rule for the path or object name. |
--filter-from | stringArray | Specifies that the filter rule for the path or object name is read from the rules file. |
-f, --force | / | Specifies that the command is forcibly run without a prompt for confirmation. |
--include | stringArray | The inclusion rule for the path or object name. |
--include-from | stringArray | Specifies that the inclusion rule is read from the rules file. |
--limited-num | int | The maximum number of results to return. |
--list-objects | / | Specifies that the ListObjects operation is called to list objects. |
--max-age | Duration | Specifies that the objects whose last modified time is earlier than the value of the --max-age parameter are not transferred. The default unit is seconds. The unit can be milliseconds, seconds, minutes, hours, days, weeks, months, or years. By default, this parameter is left empty. |
--max-mtime | Time | Specifies that the objects whose last modified time is later than the value of the --max-mtime parameter are not transferred. The value is in UTC. By default, this parameter is left empty. |
--max-size | SizeSuffix | Specifies the maximum size of the object that can be transferred. The default unit is bytes. The unit of object size can be bytes, KiB, MiB, GiB, TiB, or PiB. Note: 1 KiB = 1024 bytes. |
--metadata-exclude | stringArray | The exclusion rule for object metadata. |
--metadata-filter | stringArray | The filter rule for object metadata. |
--metadata-filter-from | stringArray | Specifies that the filter rule for object metadata is read from the rules file. |
--metadata-include | stringArray | The inclusion rule for object metadata. |
--min-age | Duration | Specifies that the objects whose last modified time is later than the value of the --min-age parameter are not transferred. The default unit is seconds. The unit can be milliseconds, seconds, minutes, hours, days, weeks, months, or years. By default, this parameter is left empty. |
--min-mtime | Time | Specifies that the objects whose last modified time is earlier than the value of the --min-mtime parameter are not transferred. The value is in UTC. By default, this parameter is left empty. |
--min-size | SizeSuffix | Specifies the minimum size of the object that can be transferred. The default unit is bytes. The unit of object size can be bytes, KiB, MiB, GiB, TiB, or PiB. Note: 1 KiB = 1024 bytes. |
--page-size | int | The maximum number of objects that can be returned. Default value: 1000. Valid values: 1 to 1000. |
-r, --recursive | / | Specifies that the command is recursively run on objects. If this parameter is specified, the command takes effect on all objects that meet the conditions in the bucket. Otherwise, the command takes effect on only the objects in the specified path. |
--request-payer | string | Specifies the payer of the request. If pay-by-requester is enabled for the bucket, set this parameter to requester. |
--start-after | string | Specifies that objects whose names are alphabetically after the value of the --start-after parameter are returned. |
For more information, see Command-line options.
Examples
Calculate the hash of a local file named example.txt:
ossutil hash md5 example.txt
Calculate and base64-encode the hash of a local file named example.txt:
ossutil hash md5 example.txt --base64
Calculate the CRC-64 of a local file named example.txt:
ossutil hash crc64 example.txt
Calculate the hash of local files in a directory named folder:
ossutil hash md5 folder/ -r
Calculate and base64-encode the hash of local files in a directory named folder:
ossutil hash md5 folder/ -r --base64
Calculate the CRC-64 of local files in a directory named folder:
ossutil hash crc64 folder/ -r
Calculate the hash of an object named example.txt in a bucket namedexamplebucket:
ossutil hash md5 oss://examplebucket/example.txt