比较来自世界各地的卖家的域名和 IT 服务价格

控制台中的模糊文件搜索 linux

有谁知道从控制台执行快速模糊搜索的方法 linux?

当我需要在项目中找到一个文件时,我经常遇到这种情况,但我不记得文件的确切名称。 在
http://www.sublimetext.com/2
我会按下 Ctrl-P 并排得出一个名称的一部分,该部分将显示要选择的文件列表。 这是我完全满意的一个惊人的功能。 问题是,在大多数情况下,我必须通过远程机器上查看控制台中的代码 ssh. 因此,我想知道是否有一个像函数的工具 "Go Anywhere" 对于控制台 Linux?
已邀请:

知食

赞同来自:

你可以找到
https://github.com/junegunn/fzf
有用。 这是一个写的普遍模糊的寻求者 Go, 它可以与任何物品列表一起使用:文件,流程,团队历史,分支机构 git 等等。

其安装脚本将配置密钥绑定。
CTRL-T

为您 shell. 下列的 GIF 展示它是如何工作的。

卫东

赞同来自:

大多数这些答案都不会执行模糊搜索,如它 sublime text - 它们可以与部分答案一致,但它们并不是良好的行为 "只需找到此顺序的所有字母。".

我认为它有点接近你想要的东西。 我收集了一个特殊的版本 cd /'fcd'/, 它使用模糊搜索来搜索目标目录。 超级简单 - 只是把它添加到你的 bashrc:


function joinstr { local IFS="$1"; shift; echo "$*"; }
function fcd { cd $/joinstr \* $/echo "$*" | fold -w1//* }


这将补充 * 在输入数据中的每个字母之间,所以如果我想去,例如,


/home/dave/results/sample/today


我可以简单地输入以下任何一种:


fcd /h/d/r/spl/t
fcd /h/d/r/s/t
fcd /h/d/r/sam/t
fcd /h/d/r/s/ty


使用首先作为示例,它将执行
cd /*h*/*d*/*r*/*s*p*l*/*t*

并将允许 shell 弄清楚实际上是什么。

只要第一个角色是忠诚的,并且写在每个目录的一个字母上写着,它就会找到你正在寻找的东西。 也许你可以为您的需求进行调整? 一个重要的一点是:


$/joinstr \* $/echo "$*" | fold -w1//*


是什么创建了模糊的搜索字符串。

奔跑吧少年

赞同来自:

设想
https://github.com/clvv/fasd
shell, 可能也值得看。


fasd

提供对shell的文件和目录的快速访问 POSIX. 他受到这些文书的启发 autojump, z 和 v. Fasd 跟踪所处理的文件和目录,以便在命令行中快速地引用它们。

它与所有文件的完整搜索略有不同,因为它只能寻找

最近开放

文件。 但是,它仍然非常有用。

君笑尘

赞同来自:

我经常使用:


ls -R | grep -i [whatever I can remember of the file name]


从目录中,我期望文件的位置更高 - 目录树中升起的越高,它将发生较慢。

当我找到文件的确切名称时,我将使用它 find:


find . [discovered file name]


它可以滚成一行:


for f in $/ls --color=never -R | grep --color=never -i partialName/; do find -name $f; done


/我发现了这个问题 LS 和 grep 有假名 "--color=auto"/

知食

赞同来自:

find . -iname '*foo*'


意外注册搜索文件名包含
foo

.

江南孤鹜

赞同来自:

https://github.com/sharkdp/fd
- 这是一个简单,快捷方便的替代品。

从项目页面中的演示版本 GitHub:

冰洋

赞同来自:

你可能想要尝试
http://www.tgries.de/agrep/
或者使用正则表达式库的其他内容
http://laurikari.net/tre/
.

/从他们的网站

:/


TRE is a lightweight, robust, and efficient POSIX compliant regexp matching library with some exciting features such as approximate /fuzzy/ matching.
At the core of TRE is a new algorithm for regular expression matching with submatch addressing. The algorithm uses linear worst-case time in the length of the text being searched, and quadratic worst-case time in the length of the used regular expression. In other words, the time complexity of the algorithm is O/M2N/, where M is the length of the regular expression and N is the length of the text. The used space is also quadratic on the length of the regex, but does not depend on the searched string. This quadratic behaviour occurs only on pathological cases which are probably very rare in practice.

TRE is not just yet another regexp matcher. TRE has some features which are not there in most free POSIX compatible implementations. Most of these features are not present in non-free implementations either, for that matter.

Approximate pattern matching allows matches to be approximate, that is, allows the matches to be close to the searched pattern under some measure of closeness. TRE uses the edit-distance measure /also known as the Levenshtein distance/ where characters can be inserted, deleted, or substituted in the searched text in order to get an exact match. Each insertion, deletion, or substitution adds the distance, or cost, of the match. TRE can report the matches which have a cost lower than some given threshold value. TRE can also be used to search for matches with the lowest cost.

莫问

赞同来自:

我不知道你熟悉的程度 terminal, 但它可以帮助你:


find | grep 'report'
find | grep 'report.*2008'


对不起,如果你已经知道了
grep

他们正在寻找更先进的东西。

卫东

赞同来自:

你可以做到以下


grep -iR "text to search for" .


在哪里 ". " 是起点,所以你可以做一些这样的事情


grep -iR "text to search" /home/


它将力量 grep 在每个文件中搜索此文本 /home/ 并列出包含此文本的文件。

窦买办

赞同来自:

你可以试试 c- /
https://github.com/whitebob/cminus
/, 模糊工具改变 dir 脚本 bash, 使用完成 bash. 只有在恰逢访问的路径中,它是某种限制的,但它真的很舒适,非常快。

https://i.stack.imgur.com/yEZ8e.gif
GitHub 项目:
https://github.com/whitebob/cminus
介绍 YouTube:
https://youtu.be/b8Bem53Cz9A

风见雨下

赞同来自:

你可能会使用 find, 这是如何为复杂的 regex:


find . -type f -regextype posix-extended -iregex ".*YOUR_PARTIAL_NAME.*" -print


或者这是为了更简单的全球巧合:


find . -type f -name "*YOUR_PARTIAL_NAME*" -print


或者你也可以使用 find2perl /这比它更快和优于 find/, 例如:


find2perl . -type f -name "*YOUR_PARTIAL_NAME*" -print | perl


如果你只是想看看如何 Perl 它确实,删除部分
| perl

, 您将看到它生成的代码。 顺便说一下,这是一种非常好的学习方式。

也写一个快速包装 bash, 与此类似,每当您想要时都会调用:


#! /bin/bash
FIND_BASE="$1"
GLOB_PATTERN="$2"
if [ $# -ne 2 ]; then
echo "Syntax: $/basename $0/ <find_base> <glob_pattern>"
else
find2perl "$FIND_BASE" -type f -name "*$GLOB_PATTERN*" -print | perl
fi


说出这件事
qsearch

, 然后将其命名为:
qsearch . something


</glob_pattern></find_base>

要回复问题请先登录注册