Answers:
安装gnome-search-tool。
sudo apt-get install gnome-search-tool
打开Search for files
选择Select More Options
并
which gnome-search-tool
= /usr/bin/gnome-search-tool
...但是当我在gnome中打开搜索选项(转到,搜索文件...)时,“选择更多选项”没有选择
gnome-search-tool
我相信您会看到它。
这是可用于搜索文件中特定文本字符串的各种方法的概述,并添加了一些选项,专门用于仅处理文本文件,而忽略二进制/应用程序文件。
但是,应该注意,搜索单词可能会有些复杂,因为大多数行匹配工具都会尝试在行中的任何位置查找单词。如果我们谈论的单词是字符串,它可能出现在行的开头或结尾,或者单独出现在行中,或者被空格和/或标点符号包围-那时我们将需要正则表达式,尤其是那些来自Perl。例如,在这里,我们可以使用-P
in grep
来使用Perl正则表达式来包围它。
$ printf "A-well-a don't you know about the bird?\nWell, everybody knows that the bird is a word" | grep -noP '\bbird\b'
1:bird
2:bird
$ grep -rIH 'word'
-r
从当前目录递归搜索-I
忽略二进制文件-H
输出找到匹配项的文件名仅适用于搜索。
$ find -type f -exec grep -IH 'word' {} \;
find
递归搜索部分-I
选项是忽略二进制文件-H
输出找到行的文件名与subshell中其他命令结合的好方法,例如:
$ find -type f -exec sh -c 'grep -IHq "word" "$1" && echo "Found in $1"' sh {} \;
#!/usr/bin/env perl
use File::Find;
use strict;
use warnings;
sub find_word{
return unless -f;
if (open(my $fh, $File::Find::name)){
while(my $line = <$fh>){
if ($line =~ /\bword\b/){
printf "%s\n", $File::Find::name;
close($fh);
return;
}
}
}
}
# this assumes we're going down from current working directory
find({ wanted => \&find_word, no_chdir => 1 },".")
这就是“打击方式”。不理想,安装grep
或perl
安装后可能没有充分的理由使用它。
#!/usr/bin/env bash
shopt -s globstar
#set -x
grep_line(){
# note that this is simple pattern matching
# If we wanted to search for whole words, we could use
# word|word\ |\ word|\ word\ )
# although when we consider punctuation characters as well - it gets more
# complex
case "$1" in
*word*) printf "%s\n" "$2";;
esac
}
readlines(){
# line count variable can be used to output on which line match occured
#line_count=1
while IFS= read -r line;
do
grep_line "$line" "$filename"
#line_count=$(($line_count+1))
done < "$1"
}
is_text_file(){
# alternatively, mimetype command could be used
# with *\ text\/* as pattern in case statement
case "$(file -b --mime-type "$1")" in
text\/*) return 0;;
*) return 1;;
esac
}
main(){
for filename in ./**/*
do
if [ -f "$filename" ] && is_text_file "$filename"
then
readlines "$filename"
fi
done
}
main "$@"
问题很老...无论如何...当前(2016年)有一个名为tracker
(您可以在ubuntu存储库中找到)的gnome应用程序,可以安装该应用程序来搜索文件内的文本(尝试过odt-ods-odp-pdf) 。该软件包随附要安装的其他4个软件包(tracker-extract,tracker-gui,tracker-miner-fs,tracker-utils)Namastè:)
更加简单快捷的是“银色搜索器” sudo apt-get install silversearcher-ag
。看看https://github.com/ggreer/the_silver_searcher,以了解为什么它比ack *更好。
grep -r word .
。