我将如何使用find来收集所有目录的路径,而不是我想要的目录中任何子目录的路径



我正在尝试收集每个以字母"开头的目录的完整路径;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

我尝试使用-prenme作为:

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

相关内容

最新更新