寻求类似gnome-search-tool的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: Tellslocate/plocateto 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 withdocs(ensuring we get directories, not files nameddocs).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

