简体   繁体   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

I'm trying to collect the full pathways of every directory starting with the letter "K" in a large parent directory containing several hundred files and directories.我正在尝试在包含数百个文件和目录的大型父目录中收集以字母“K”开头的每个目录的完整路径。 Each of the directories also has subdirectories;每个目录也有子目录; the paths of which I don't want.我不想要的路径。 I wanted to list all of my directory pathways in a file called samples.txt.我想在一个名为 samples.txt 的文件中列出我的所有目录路径。 My data is structured like this:我的数据结构如下:

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

I have tried this command and was able to get a samples.txt file with only the paths of the K1-K500 files that I wanted, but I still get the unwanted paths of all of the subdirectories too.我已经尝试过这个命令,并且能够得到一个 samples.txt 文件,其中只有我想要的 K1-K500 文件的路径,但我仍然得到了所有子目录的不需要的路径。

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

I tried using -prune as:我尝试使用 -prune 作为:

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

However, this just left me with an entirely blank samples.txt file.然而,这只是给我留下了一个完全空白的 samples.txt 文件。 What edits should I make to give me only the K* directories, but not any subdirectories?我应该进行哪些编辑才能只给我 K* 目录,而不给我任何子目录? Thanks in advance!提前致谢!

This should achieve what you wanted:这应该可以实现您想要的:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何查找包含特定目录的路径的所有文件 - How to find all files which paths contains a specific directories 我如何递归grep所有目录和子目录? - How do I recursively grep all directories and subdirectories? 如何在 Linux 的两个目录中找到相似的文件 - How can I find similar files within two directories in Linux 如何使用 grep 提取目录和子目录中所有文件中包含的所有 IP 地址? - How can I use grep to extract all IP addresses contained in all the files within a directory and sub-directories? 我只想将目录及其子目录的内容复制到一个目录而不复制目录和子目录 - I want to only the contents of directories and his subdirectories to a directory without copying the directory and subdirectory 解压目录和子目录中的所有 .gz - untar all .gz in directories and subdirectories 如何查找具有特定名称的所有子目录并删除其内容(而不是删除目录本身) - How to find all subdirectories with a specific name and delete its contents (and NOT delete the directories themselves) 如何将多个目录展平并覆盖到一个目录中? - How would I flatten and overlay multiple directories into one directory? 如何列出(对于给定的两个目录)树下具有相同名称和相对路径的目录。 - How to list (for given two directories) the directories with the same names and relative paths under the trees. 在bash脚本中使用中间的父“..”目录规范化路径 - Normalize paths with parent “..” directories in the middle in bash script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM