zoukankan      html  css  js  c++  java
  • 专业素养:发布文件,别忘了给出校验信息

    Q: 我这明明好用的,他那怎么就不行,怎么办?

    A: 先对比下文件信息,别只是上传下载中断罢了。

    sha256 校验码

    sha256sum <file> 输出 sha256 文件校验信息。

    $ sha256sum test.txt
    f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2  test.txt
    
    $ sha256sum test.txt | cut -d ' ' -f 1
    f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2
    

    文件大小

    du -h <file> 输出 "Human-readable" 文件大小信息。

    $ du -h test.txt
    4.0K	test.txt
    
    $ du -h test.txt | cut -f 1
    4.0K
    

    写个脚本

    info.sh

    #!/usr/bin/env bash
    
    if [ $# -eq 0 ]; then
      echo "Usage: ./info.sh <file or directory>"
      exit 1
    fi
    
    _info() {
      file="$1"
      echo "file: `basename "$file"`"
      echo "size: `du -h "$file" | cut -f 1`"
      echo "sha256: `sha256sum "$file" | cut -d ' ' -f 1`"
      echo
    }
    
    for path in "$@"; do
      if [ -d "$path" ]; then
        find "$path" -type f | while read -r f; do
          _info "$f"
        done
      else
        _info "$path"
      fi
    done
    

    使用

    $ ./info.sh test.txt
    file: test.txt
    size: 4.0K
    sha256: f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2
    

    写进文件:

    $ file=test.txt && ./info.sh "$file" > $(basename "$file").info
    
    $ cat test.txt.info
    file: test.txt
    size: 4.0K
    sha256: f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2
    

    测试

    macOS Ubuntu

    结语

    发布文件,别忘了给出校验信息哟~

  • 相关阅读:
    机器学习笔记[保持更新]
    习题 7-3 uva211
    习题 7-2 uva225(回溯)
    习题7-1 uva 208(剪枝)
    poj2331 (IDA*)
    poj2449 (第k条最短路)
    POJ 1324(BFS + 状态压缩)
    hdu3567 八数码(搜索)--预处理
    poj 1367 robot(搜索)
    例 7-10 uva12212(迭代加深搜索)
  • 原文地址:https://www.cnblogs.com/gocodinginmyway/p/12976976.html
Copyright © 2011-2022 走看看