在 RedHat 中工作的正規表示式在 Ubuntu 中沒有給出任何結果

在 RedHat 中工作的正規表示式在 Ubuntu 中沒有給出任何結果

我的目標是匹配特定子目錄中的特定檔案。我有以下資料夾結構

`--數據
    |-- 一個
    |-- a.txt
    |-- b
    |-- b.txt
    |-- c
    |-- c.txt
    |-- d
    |-- d.txt
    |-- e
    |-- e.txt
    |-- 組織-1
    | |-- a.org
    | |-- b.org
    | |-- org.txt
    | |-- 用戶-0
    | | |-- a.txt
    | | |-- b.txt

我試圖僅列出資料目錄內的文件。我能夠在 RHEL 中使用以下命令獲得正確的結果

尋找 ./testdir/ -iwholename "*/data/[!/].txt"
a.txt
b.txt
c.txt
d.txt
e.txt

如果我在 Ubuntu 中運行相同的命令,它就不起作用。

誰能告訴我為什麼它在 Ubuntu 中不起作用?

編輯:

經過一些測試後,我意識到根據我的帖子,它在 RHEL 和 Ubuntu 中都能正常工作。問題出在其他地方。我的 Ubuntu 系統中的檔案是資料檔。

非常奇怪的是,對於這些文件類型,它沒有在 RHEL 和 Ubuntu 中同時列出。

[supratik@testserver ~]$ ls testprog/data/
a.txt 數據.dat

[supratik@testserver ~]$ 檔案 testprog/data/a.txt
testprog/data/a.txt:ASCII 文字

[supratik@testserver ~]$ 檔案 testprog/data/data.dat
testprog/data/data.dat:數據

[supratik@testserver ~]$ find ./testprog/ -iwholename "*/data/[!/].txt"
./testprog/data/a.txt

[supratik@testserver ~]$ find ./testprog/ -iwholename "*/data/[!/].dat"

答案1

我剛剛在 CentOS 5.6,6.0 和 Ubuntu 9.04,10.04 和 11.04 上檢查過這個,我得到了相同的答案,即

find  ./testdir/ -iwholename "*/data/[!/].txt"
./testdir/data/c.txt
./testdir/data/d.txt
./testdir/data/a.txt
./testdir/data/e.txt
./testdir/data/b.txt

您可以獲得類似的結果

Find ./testdir/data/ -maxdepth 1 -name '*.txt'

相關內容