Compare sdk/tools for directory and files.
- Support comparing files or directories result is equals.
- Supports comparing files or directories with the difference list.
- Support for calculating the hash of a file or directories md5/sha1/sha256/sha512.
- This library supports both SDK and CLI tools.
- CLI support result format : table/json/csv/yaml
- CLI support result output to a file.
go get -u github.com/foolin/sumdiff
//Compare
ok, result, err := sumdiff.Cmp(path1, path2)
//Equal
ok, err := sumdiff.Equal(v.path1, v.path2)
sumdiff --help
A useful comparison tool for differences and hash
Usage:
sumdiff [command]
Available Commands:
cmp Compare the two files or directories are different
completion Generate the autocompletion script for the specified shell
eq Compare whether two files or directory are equal
hash Calculate hash algorithm [md5|sha1|sha256|sha512] hex string
help Help about any command
md5 Calculate md5 hex string
sha1 Calculate sha1 hex string
sha256 Calculate sha256 hex string
Flags:
-f, --format string Format: table|json|csv|yaml (default "table")
-h, --help help for sumdiff
-o, --output string Output filename
-v, --verbose Verbose output info
Use "sumdiff [command] --help" for more information about a command.
-
Compare the two files or directories are equal
sumdiff eq <path1> <path2>
Example1:
sumdiff eq test_data/a.txt test_data/b.txt
Output1:
+--------+ | result | +--------+ | true | +--------+
Example2:
sumdiff eq test_data/c.txt test_data/d.txt
Output2:
false
- Compare the two file or directory differences
sumdiff diff <path1> <path2>
Example:
sumdiff cmp test_data/data1 test_data/data3
Output:
+-------------------------------------------+
| Path | OK | Msg |
+-------------------------------------------+
| | true | |
| /a.txt | true | |
| /b.txt | true | |
| /c.txt | false | path1 not exist [/c.txt] |
+-------------------------------------------+
false
Calculate the MD5 hexadecimal value of the files or directories
sumdiff md5 <path1> [<path2>] [<path3>] ...
Example:
sumdiff md5 test_data/a.txt
Output:
+-----------------------------------------------------------+
| Hash | Size | Path |
+-----------------------------------------------------------+
| 9d15fa011b54dbd079d1d20e36e4a358 | 212 | test_data/a.txt |
+-----------------------------------------------------------+
Calculate the MD5 hexadecimal value of the files or directories
sumdiff sha1 <path1> [<path2>] [<path3>] ...
Example:
sumdiff sha1 test_data/data1
Output:
+---------------------------------------------------------------+
| Hash | Size | Path |
+---------------------------------------------------------------+
| 18b012c3e30bf822589ac96fd4d87e6e8d89754e | 4096 | data1/a.txt |
| 9c678f3b44c0918f5695e5a0a8232ab1b017a4a4 | 4096 | data1/b.txt |
+---------------------------------------------------------------+
sumdiff sha256 <path1> [<path2>] [<path3>] ...
Example:
sumdiff sha256 test_data/a.txt test_data/c.txt
Output:
+-------------------------------------------------------------------------------------------+
| Hash | Size | Path |
+-------------------------------------------------------------------------------------------+
| bb3cf386d0c975847024b0d78c9f92c0657c894f16c1db1248233cfe2b05b65f | 212 | test_data/a.txt |
| 732d2d9a2c39480fa38bd060f07b3e55eb3b47888e8019a8d4cfd8600d5c104f | 222 | test_data/c.txt |
+-------------------------------------------------------------------------------------------+
Calculate the hash(md5|sha1|sha256|sha512) value of a file or directory
sumdiff hash <md5|sha1|sha256|sha512> <path1> [<path2>] [<path3>] ...
Example:
sumdiff hash sha512 test_data/a.txt
Output:
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Hash | Size | Path |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
| 9683aedddcc5b16548f3510580d91306fad405070fd516299e3f5609bff5fd950a1a6e39e8bce5000d4f3c264428855eb2ae0f235f55d89bd9ec2c9f02c86c4b | 212 | test_data/a.txt |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
sumdiff -h
linux:
tar -xvf sumdiff_Linux_x86_64.tar.gz && sudo mv sumdiff /usr/local/bin