How to sort the results of find (including nested directories) alphabetically in bash

后端 未结 3 1772
心在旅途
心在旅途 2021-02-04 12:58

I have a list of directories based on the results of running the \"find\" command in bash. As an example, the result of find are the files:

test/a/file
test/b/fi         


        
3条回答
  •  北海茫月
    2021-02-04 13:30

    If you want to sort alphabetically, the best way is:

    find test -print0 | sort -z
    

    (The example in the original question actually wanted files before directories, which is not the same and requires extra steps)

提交回复
热议问题