【问题标题】:How would I use find to collect the paths of all directories, but not the paths of any subdirectories within the directories I want我将如何使用 find 来收集所有目录的路径,而不是我想要的目录中任何子目录的路径
【发布时间】:2020-12-19 18:50:35
【问题描述】:

我正在尝试在包含数百个文件和目录的大型父目录中收集以字母“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* 目录,而不是任何子目录?提前致谢!

【问题讨论】:

    标签: linux unix command-line find


    【解决方案1】:

    这应该可以实现您想要的:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-18
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 2016-01-17
      • 2021-02-11
      • 1970-01-01
      • 2013-09-14
      相关资源
      最近更新 更多