簡體   English   中英

我將如何使用 find 來收集所有目錄的路徑,而不是我想要的目錄中任何子目錄的路徑

[英]How would I use find to collect the paths of all directories, but not the paths of any subdirectories within the directories I want

我正在嘗試在包含數百個文件和目錄的大型父目錄中收集以字母“K”開頭的每個目錄的完整路徑。 每個目錄也有子目錄; 我不想要的路徑。 我想在一個名為 samples.txt 的文件中列出我的所有目錄路徑。 我的數據結構如下:

Parent_Directory
|
|__K1
|  |
|  |_Unnecessary_Directory1
|  |
|  |_Unnecessary_Directory2
|
|__K2
|  |
|  |_Unnecessary_Directory1
|  |
|  |_Unnecessary_Directory2
|
K3-K500, Several other unwanted directories/files

我已經嘗試過這個命令,並且能夠得到一個 samples.txt 文件,其中只有我想要的 K1-K500 文件的路徑,但我仍然得到了所有子目錄的不需要的路徑。

find /Rest/of/Path/Parent_Directory/K* -type d > samples.txt

我嘗試使用 -prune 作為:

find /Rest/of/Path/Parent_Directory/K* -type d -prune -o -name 'Un*' > samples.txt

然而,這只是給我留下了一個完全空白的 samples.txt 文件。 我應該進行哪些編輯才能只給我 K* 目錄,而不給我任何子目錄? 提前致謝!

這應該可以實現您想要的:

find /Rest/of/Path/Parent_Directory/K* -type d -prune

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM