AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 662339
Accepted
UTF-8
UTF-8
Asked: 2015-08-17 19:22:52 +0800 CST2015-08-17 19:22:52 +0800 CST 2015-08-17 19:22:52 +0800 CST

处理前按字母顺序对文件排序

  • 772

我使用命令

find . -type f -exec sha256sum {} \; > sha256SumOutput

散列文件夹层次结构中的每个文件。不幸的是,sha256sum没有find按字母顺序获取文件名。这怎么能解决?

我希望在对它们进行哈希处理之前对其进行排序,以便按字母顺序对它们进行哈希处理(这是有原因的)。

find
  • 2 2 个回答
  • 49005 Views

2 个回答

  • Voted
  1. Best Answer
    A.B.
    2015-08-17T22:21:11+08:002015-08-17T22:21:11+08:00

    使用一些管道和sort

    find . -type f -print0 | sort -z | xargs -r0 sha256sum > sha256SumOutput
    

    解释

    从man find

       -print0
            True; print the full file name on the standard output, followed
            by a null character (instead of the newline character that -print
            uses). This allows file names that contain newlines or other
            types of white space to be  correctly  interpreted by programs
            that process the find output.  This option corresponds to the -0
            option of xargs.
    

    从man sort

       -z, --zero-terminated
            line delimiter is NUL, not newline
    

    从man xargs

       -r
            If the standard input does not contain any nonblanks, do not run
            the command. Normally, the command is run once even if there is
            no input. This option is a GNU extension.
    
       -0   
            Input items are terminated by a null character instead of by
            whitespace, and the quotes and backslash are not special (every
            character is taken literally).  Disables the end of file string,
            which is treated like any  other  argument. Useful when input
            items might contain white space, quote marks, or backslashes.
            The GNU find -print0 option produces input suitable for this mode.
        
    

    例子

    % ls -laog
    total 4288
    drwxrwxr-x  2 4329472 Aug 17 08:20 .
    drwx------ 57   20480 Aug 17 08:20 ..
    -rw-rw-r--  1       0 Aug 17 08:15 a
    -rw-rw-r--  1       0 Aug 17 08:15 a b
    -rw-rw-r--  1       0 Aug 17 08:15 b
    -rw-rw-r--  1       0 Aug 17 08:15 c
    
    % find -type f -print0 | sort -z | xargs -r0 sha256sum                  
    e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  ./a
    e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  ./a b
    e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  ./b
    e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  ./c
    

    第一列中的值相同,因为文件在我的测试中没有任何内容。

    • 36
  2. user3591723
    2015-08-17T19:27:11+08:002015-08-17T19:27:11+08:00

    您应该能够将您的输出从管道find传输到sort.

    • 1

相关问题

  • 尝试在当前目录中查找所有 jpg 文件时出现“路径必须先于表达式”错误

  • 使用 locate 查找目录

  • Bash 脚本的问题

  • 创建最近创建的文件的目录

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve