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

寻求类似gnome-search-tool的CLI工具:支持目录名分组且基于索引

解决方案:目录名匹配+分组展示的CLI索引搜索工具

Got it, let's tackle this problem for you. You want a CLI tool that works like gnome-search-tool but focuses on matching directory names (not full paths), groups results by the matched directory name, and keeps the fast indexed search speed that locate provides. Here are a few solid solutions:

方案1:用mlocate/plocate + 命令行工具组合(无需额外安装)

Most systems come with mlocate (the default locate on many distros) or plocate (a faster, modern alternative) pre-installed—both rely on the system's indexed database (updated via updatedb), so they keep that lightning-fast search speed you need.

To search for a directory named docs and group results by the directory name, run:

# For mlocate
locate -b "\docs" | grep -E "/docs$" | sort | awk -F/ '{
    if ($NF != current) {
        current = $NF
        print "\n" current ":"
    }
    print "  " $0
}'

# For plocate (faster alternative)
plocate -b "\docs" | grep -E "/docs$" | sort | awk -F/ '{
    if ($NF != current) {
        current = $NF
        print "\n" current ":"
    }
    print "  " $0
}'

命令解释:

  • -b: Tells locate/plocate to only match the basename (the last part of the path), avoiding full-path matches that clutter results.
  • grep -E "/docs$": Filters results to only keep paths ending with docs (ensuring we get directories, not files named docs).
  • sort: Ensures results are ordered so identical directory names are grouped together.
  • awk: Handles the grouping logic—prints the directory name as a header, then lists all matching paths under it.

方案2:自定义脚本实现一键分组搜索

If you want a more streamlined workflow, wrap the logic into a reusable script. Save this as dirindexsearch.sh:

#!/bin/bash

if [ -z "$1" ]; then
    echo "Usage: $0 <directory-name>"
    exit 1
fi

SEARCH_TERM="$1"

# Use plocate if available, fall back to mlocate
if command -v plocate &> /dev/null; then
    plocate -b "\${SEARCH_TERM}" | grep -E "/${SEARCH_TERM}$" | sort | awk -F/ '{
        if ($NF != current) {
            current = $NF
            print "\n" current ":"
        }
        print "  " $0
    }'
else
    locate -b "\${SEARCH_TERM}" | grep -E "/${SEARCH_TERM}$" | sort | awk -F/ '{
        if ($NF != current) {
            current = $NF
            print "\n" current ":"
        }
        print "  " $0
    }'
fi

Then make it executable:

chmod +x dirindexsearch.sh

Now you can run it with just:

./dirindexsearch.sh docs

This script auto-detects which indexed search tool you have installed, so it works across most Linux distros.

关键优势

All these solutions use the system's pre-built search index (maintained by updatedb), so they're just as fast as locate—no slow real-time filesystem scanning like find would do. And the grouping logic mimics the clean, organized output you liked from gnome-search-tool.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 07:53:36