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

后端 未结 3 1779
心在旅途
心在旅途 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:34

    try this. for reference, it firsts sorts on the second field second char. which only exists on the file, and has a r for reverse meaning it is first, after that it will sort on the first char of the second field. [-t is field deliminator, -k is key]

    find test -name file |sort -t'/' -k2.2r -k2.1
    

    do a info sort for more info. there is a ton of different ways to use the -t and -k together to get different results.

提交回复
热议问题