51

Linuxコンソールからあいまい検索をすばやく実行する方法を知っている人はいますか?

プロジェクト内のファイルを検索する必要があるときに、正確なファイル名を覚えていないという状況によく遭遇します。Sublime テキスト エディターでCtrl-P を押して名前の一部を入力すると、選択するファイルのリストが生成されます。それは私が非常に満足している素晴らしい機能です。問題は、ほとんどの場合、ssh を介してリモート マシンのコンソールでコードを参照する必要があることです。それで、Linux コンソール用の「どこでも移動」機能に似たツールがあるのだろうか?

4

12 に答える 12

70

fzfが役立つ場合があります。ファイル、プロセス、コマンド履歴、git ブランチなど、あらゆるリストで使用できる、Go で書かれた汎用のファジー ファインダーです。

そのインストール スクリプトはCTRL-T、シェルのキーバインドを設定します。次の GIF は、その仕組みを示しています。

于 2013-11-06T06:11:46.573 に答える
5

fasdシェル スクリプトも一見の価値があります。

fasdPOSIX シェルのファイルとディレクトリにすばやくアクセスできます。autojump、z、v などのツールに着想を得ています。Fasd は、アクセスしたファイルとディレクトリを追跡するため、コマンド ラインでそれらをすばやく参照できます。

最近開いたファイルのみを検索するため、すべてのファイルの完全な検索とは少し異なります。ただし、それでも非常に便利です。

于 2013-01-30T04:34:45.457 に答える
5
find . -iname '*foo*'

を含むファイル名の大文字と小文字を区別しない検索foo

于 2014-02-21T15:58:34.087 に答える
4

私は通常使用します:

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

ファイルがあると思われる場所の上のディレクトリから-ディレクトリツリーの上位に行くほど、これは遅くなります。

正確なファイル名が見つかったら、それを検索で使用します。

find . [discovered file name]

これは 1 行にまとめることができます。

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

(ls と grep が "--color=auto" にエイリアスされていることに問題があることがわかりました)

于 2012-02-25T00:08:44.527 に答える
2

あなたが端末にどれだけ精通しているかはわかりませんが、これは役に立ちます:

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

grepすでに知っていて、より高度なものを探していた場合は申し訳ありません。

于 2012-02-24T22:52:03.890 に答える
1

AGREPなど、 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.
于 2012-02-24T22:51:33.313 に答える
1

次のことができます

grep -iR "text to search for" .

どこ "。" 開始点であるため、次のようなことができます

grep -iR "text to search" /home/

これにより、grep は /home/ の下のすべてのファイル内の指定されたテキストを検索し、そのテキストを含むファイルを一覧表示します。

于 2012-02-24T22:59:32.910 に答える