Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何使用find收集所有目录的路径,而不是我想要的目录中任何子目录的路径_Linux_Unix_Command Line_Find - Fatal编程技术网

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

Linux 如何使用find收集所有目录的路径,而不是我想要的目录中任何子目录的路径,linux,unix,command-line,find,Linux,Unix,Command Line,Find,我试图收集包含数百个文件和目录的大型父目录中以字母“K”开头的每个目录的完整路径。每个目录也有子目录;我不想要的路。我想在一个名为samples.txt的文件中列出我所有的目录路径。我的数据结构如下: Parent_Directory | |__K1 | | | |_Unnecessary_Directory1 | | | |_Unnecessary_Directory2 | |__K2 | | | |_Unnecessary_Directory1 | | | |_Unneces

我试图收集包含数百个文件和目录的大型父目录中以字母“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