sum 命令详解

| 选择喜欢的代码风格  

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

sum 命令安装:


-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 命令补充说明:


sum 命令用于计算文件的校验和和块数。 是 cksum 命令的前身,提供 sum 命令是为了兼容性; 在新应用程序中一般优先用 cksum 命令

sum 命令和 cksum 命令区别:


sum 和 cksum 命令都用于计算文件的校验和,但它们使用的校验和算法和输出格式略有不同。以下是它们之间的主要区别:

  1. 校验和算法
    • sum 命令通常使用 BSD 校验和算法,也称为 CRC-32 校验和算法。
    • cksum 命令使用 POSIX 校验和算法,也称为 CRC-32 校验和算法的一种变体。

  2. 输出格式
    • sum 命令的输出格式是两个数字,分别是文件的校验和和文件的字节数,以空格分隔。
    • cksum 命令的输出格式包括三个数字,分别是文件的校验和、文件的字节数以及文件的名称,这些数字由空格分隔。

sum 命令语法:


sum [options]... [file]...

sum 命令选项:


 -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 的目标文件

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)是文件中的字节数(文件大小),表示文件的大小以字节为单位。


通过比较文件的校验和,可以检查文件是否在传输或存储过程中发生了变化,以确保数据完整性。
如果两个文件的校验和相同,那么它们的内容一致。

sum 扩展阅读:




sum 命令评论