欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

find命令的結(jié)果順序是什么

 更新時(shí)間:2023年05月22日 10:55:36   作者:baiyu33  
這篇文章主要介紹了find命令的結(jié)果順序是什么,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1. 目的

在研讀 doxygen 源碼時(shí), 在不同電腦、不同操作系統(tǒng)上使用了 find 命令, 發(fā)現(xiàn)對于相同的 doxygen 源碼目錄、相同的 find 命令參數(shù), 得到了不同順序的結(jié)果。嘗試了解下 find 命令的參數(shù), 希望得到統(tǒng)一一致的結(jié)果, 對不同結(jié)果的原因稍作分析。

簡單的結(jié)論: find . -maxdepth 1 -type d 這樣的命令后, 接入管道和 sort -V 得到自然排序結(jié)果:

find . -maxdepth 1 -type d | sort -V

2. 準(zhǔn)備: 克隆 doxygen 源碼

git clone https://gitee.com/mirrors/doxygen
git checkout 79a9efb
* 79a9efb 2023-05-18 | Merge pull request #10052 from albert-github/feature/bug_regr_ca65fd0bbb717a3f65e64bfcebe36a5debba66fa (grafted, HEAD -> master, origin/master, origin/HEAD) [Dimitri van Heesch]

我們希望用 find 命令, 打印出 doxygen 目錄下的第一級子目錄。

3. ubuntu22.04 結(jié)果

(base) zz@localhost-43% cat /etc/issue
Ubuntu 22.04.1 LTS \n \l
(base) zz@localhost% find --version
find (GNU findutils) 4.8.0
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Eric B. Decker, James Youngman, and Kevin Dalley.
開啟的特性: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)
(base) zz@localhost% find . -maxdepth 1 -type d
.
./.git
./templates
./libxml
./deps
./libversion
./.github
./examples
./testing
./doc_internal
./addon
./winbuild
./doc
./src
./cmake
./vhdlparser

4. ubuntu16.04 結(jié)果

(base) zz@localhost-04% cat /etc/issue
Ubuntu 16.04.1 LTS \n \l
(base) zz@localhost-04% find --version
find (GNU findutils) 4.7.0-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)
(base) zz@localhost-04% find . -maxdepth 1 -type d
.
./.github
./src
./doc
./addon
./doc_internal
./libxml
./testing
./deps
./.git
./examples
./libversion
./templates
./cmake
./winbuild
./vhdlparser

5. git bash 結(jié)果

$ find --version
find (GNU findutils) 4.9.0
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)
$ find . -maxdepth 1 -type d
.
./.git
./.github
./addon
./cmake
./deps
./doc
./doc_internal
./examples
./libversion
./libxml
./src
./templates
./testing
./vhdlparser
./winbuild

6. 三路比較

7. 保持一樣的結(jié)果: 用自然排序

傳入 | sort -V 參數(shù)即可:

find . -maxdepth 1 -type d | sort -V
(base) zz@localhost% find . -maxdepth 1 -type d | sort -V
.
./.git
./.github
./addon
./cmake
./deps
./doc
./doc_internal
./examples
./libversion
./libxml
./src
./templates
./testing
./vhdlparser
./winbuild

8. References

https://www.baeldung.com/linux/find-default-sorting-order

關(guān)于find命令查找的排序規(guī)則探索以及排序方法

1、linux中find命令的排序規(guī)則

find命令的搜尋條件直接關(guān)系到輸出結(jié)果,默認(rèn)應(yīng)該是按從左到右的的順序判斷,如果有邏輯運(yùn)算(-not、-and、-or)還得再判斷條件組合。
find查詢的結(jié)果是找到一個(gè)匹配的項(xiàng)就立即輸出結(jié)果,一邊查找一邊輸出,查找到的內(nèi)容不是一次性輸出的,所以可能沒有統(tǒng)一排序。
但是具體排序規(guī)則需要分析find命令的底層實(shí)現(xiàn)了。

2、linux shell編程中文件查找并排序的方法

方法一:

find  dir  -name "*.txt"  | sort

方法二:

ls  $(find dir -name "*.txt")

到此這篇關(guān)于find命令的結(jié)果順序是什么的文章就介紹到這了,更多相關(guān)find命令的結(jié)果順序內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Linux中rz命令和sz命令使用詳解大全

    Linux中rz命令和sz命令使用詳解大全

    在linux中rz 和 sz 命令允許開發(fā)板與主機(jī)通過串口進(jìn)行傳遞文件了,下面我們就來簡單的介紹一下rz 和 sz 命令實(shí)例
    2015-10-10
  • 關(guān)于vi和vim的區(qū)別及命令詳解

    關(guān)于vi和vim的區(qū)別及命令詳解

    下面小編就就為大家?guī)硪黄P(guān)于vi和vim的區(qū)別及命令詳解。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01
  • Linux中修改文件權(quán)限chmod命令詳解

    Linux中修改文件權(quán)限chmod命令詳解

    在Linux系統(tǒng)中,chmod命令用于更改文件或目錄的權(quán)限,它可以授予或撤銷對文件的讀取、寫入和執(zhí)行權(quán)限,本文給大家詳細(xì)的介紹了Linux修改文件權(quán)限chmod命令用法,需要的朋友可以參考下
    2023-08-08
  • Bash中數(shù)組的操作教程

    Bash中數(shù)組的操作教程

    這篇文章主要介紹了Bash數(shù)組操,包括定義數(shù)組、讀取數(shù)組、修改數(shù)組以及數(shù)組循環(huán),文中通過示例代碼給出了詳細(xì)的介紹,有需要的朋友可以參考下,下面來一起看看吧。
    2016-12-12
  • shell腳本中 /dev/null 的用法小結(jié)

    shell腳本中 /dev/null 的用法小結(jié)

    /dev/null 通常被用于丟棄不需要的輸出流,或作為用于輸入流的空文件,這些操作通常由重定向完成,任何你想丟棄的數(shù)據(jù)都可以寫入其中,本文重點(diǎn)給大家介紹shell腳本中 /dev/null 的用法小結(jié),感興趣的朋友一起看看吧
    2021-09-09
  • Linux用腳本實(shí)現(xiàn)“時(shí)分秒“倒計(jì)時(shí)功能

    Linux用腳本實(shí)現(xiàn)“時(shí)分秒“倒計(jì)時(shí)功能

    這篇文章主要介紹了Linux用腳本實(shí)現(xiàn)“時(shí)分秒“倒計(jì)時(shí)功能,本文圖文實(shí)例相結(jié)合給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-12-12
  • git 使用及常用命令

    git 使用及常用命令

    本文是關(guān)于git 的使用和一些git使用小技巧,以及git的常用命令,進(jìn)行的整理,希望能幫助有需要的小伙伴
    2016-07-07
  • 監(jiān)控網(wǎng)站是否可以正常打開的Shell腳本分享

    監(jiān)控網(wǎng)站是否可以正常打開的Shell腳本分享

    這篇文章主要介紹了監(jiān)控網(wǎng)站是否可以正常打開的Shell腳本分享,可以指定N個(gè)網(wǎng)址,放在crontab中執(zhí)行,需要的朋友可以參考下
    2014-09-09
  • 詳解Linux  Shell 實(shí)現(xiàn)一個(gè)獲取任意位數(shù)的隨機(jī)密碼的腳本

    詳解Linux Shell 實(shí)現(xiàn)一個(gè)獲取任意位數(shù)的隨機(jī)密碼的腳本

    這篇文章主要介紹了詳解Linux Shell 實(shí)現(xiàn)一個(gè)獲取任意位數(shù)的隨機(jī)密碼的腳本的相關(guān)資料,本文提供實(shí)現(xiàn)方法及實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2017-08-08
  • cpu時(shí)鐘預(yù)取實(shí)例代碼分享

    cpu時(shí)鐘預(yù)取實(shí)例代碼分享

    cpu時(shí)鐘預(yù)取實(shí)例代碼分享,大家參考使用吧
    2013-12-12

最新評論