A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
-bash/zsh: sum: command not found # Windows (WSL2) sudo apt-get update sudo apt-get install coreutils # Debian apt-get install coreutils # Ubuntu apt-get install coreutils # Alpine apk add coreutils # Arch Linux pacman -S coreutils # Kali Linux apt-get install coreutils # CentOS yum install coreutils # Fedora dnf install coreutils # OS X brew install coreutils # Raspbian apt-get install coreutils # Dockerfile dockerfile.run/sum # Docker docker run cmd.cat/sum sum
sum 命令用于计算文件的校验和和块数。 是 cksum 命令的前身,提供 sum 命令是为了兼容性; 在新应用程序中一般优先用 cksum 命令。
sum 和 cksum 命令都用于计算文件的校验和,但它们使用的校验和算法和输出格式略有不同。以下是它们之间的主要区别:
sum [options]... [file]...
-r Use the default (BSD compatible) algorithm. This option is included for compatibility with the System V 'sum'. Unless '-s' was also given, it has no effect. -s --sysv Compute checksums using an algorithm compatible with System V 'sum''s default, and print file sizes in units of 512-byte blocks.
待 sum 的目标文件
sum 命令,使用 BSD 兼容算法和 1024 字节块计算校验和:
sum path/to/file
sum 命令使用 System V 兼容算法和 512 字节块计算校验和:
sum --sysv path/to/file
sum 命令输出结果含义:
sum 1.txt 19390 1 ========================================= 这两个数字分别代表两个不同的校验和: 第一个数字(19390)是文件的校验和,通常使用 BSD 校验和算法(CRC-32)来计算。 这个校验和用于验证文件内容的完整性,如果文件内容发生改变,校验和值将不同。 第二个数字(1)是文件中的字节数(文件大小),表示文件的大小以字节为单位。 通过比较文件的校验和,可以检查文件是否在传输或存储过程中发生了变化,以确保数据完整性。 如果两个文件的校验和相同,那么它们的内容一致。