You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取包含指定子目录/admin/news的目录列表?

解决方法

你的命令逻辑搞反了——你要找的是包含admin/news子目录的父目录,但原命令是直接查找/admin/news路径本身,自然会因为路径不存在报错。

正确命令示例

从当前目录递归搜索所有符合条件的父目录

find . -type d -path "*/admin/news" -printf '%h\n'

参数说明:

  • .:从当前工作目录开始搜索
  • -type d:仅匹配目录
  • -path "*/admin/news":匹配所有路径以admin/news结尾的目录
  • -printf '%h\n':输出该目录的父路径(也就是你要找的、包含admin/news的目录)

可选优化

  1. 限定搜索深度(比如最多向下搜索3层):
find . -maxdepth 3 -type d -path "*/admin/news" -printf '%h\n'
  1. 去重(避免同一父目录被多次输出):
find . -type d -path "*/admin/news" -printf '%h\n' | sort -u

内容的提问来源于stack exchange,提问作者L Holden

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 02:45:34