[英]Grep in Ubuntu 14.04
I just recently updated my Ubuntu VM to 14.04 and before this I could run the grep command 我最近将Ubuntu VM更新到14.04,在此之前我可以运行grep命令
grep -nr "piece of text"
or any other grep command for that matter and it would finish in 2-10 seconds in the directory I was working on. 或其他任何grep命令,它将在2-10秒内在我正在处理的目录中完成。 Now for some reason (no idea if this was caused by the update) running any grep command in the same dir I was working in just seems to hang there (idk if it does complete because I don't want to wait over a min or so for a search to happen) instead of showing my results. 现在由于某种原因(不知道这是否是由更新引起的),在我正在使用的同一个目录中运行任何grep命令似乎都挂在那里(idk如果完成了,因为我不想等待一分钟或以便进行搜索)而不是显示我的结果。 Any idea of what's happening or what I can do and try to fix it? 对正在发生的事情或我能做些什么并尝试解决它有任何想法吗?
which grep
are you using ? 您正在使用哪个grep
? -r
option default to '.' -r
选项默认为“。” directory in gnu case gnu情况下的目录
which grep :
/bin/grep --version
/bin/grep (GNU grep) 2.18)
...
this is gnu grep :
echo "truc" >/tmp/truc
cd /tmp; grep -nr "truc";
using gnu grep -> it search recursively files in . 使用gnu grep->递归搜索。 of current directory ( here in /tmp
) and displays them containing "truc" 当前目录(在/tmp
)的目录,并显示包含“ truc”的目录
if /bin/grep --version
is busybox : 如果/bin/grep --version
是busybox:
BusyBox v1.22.1 (Debian 1:1.22.0-8) multi-call binary.
Usage: 用法:
grep [-HhnlLoqvsriwFEz] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]...
using busybox : cd /tmp; busybox grep -nr "truc";
使用busybox: cd /tmp; busybox grep -nr "truc";
cd /tmp; busybox grep -nr "truc";
wait indefinitely that you type content of file on STDIN ( stop with Ctrl + C ). 无限期地等待您在STDIN上键入文件的内容(以Ctrl + C停止)。
it reads STDIN as a file ( not even caring that -n
indicates a directory recursion ). 它将STDIN读取为文件(甚至不关心-n
表示目录递归)。
As others answered, and as POSIX grep or GNU grep documentation tells, you need to specify some file to the standard grep
command. 正如其他人回答的那样,正如POSIX grep或GNU grep文档所讲的那样,您需要为标准grep
命令指定一些文件。 (But GNU grep
defaults to current directory .
if -r
is given without a directory name; however if -r
is not given at all, grep
defaults to read -
ie the stdin ). (但GNU grep
默认为当前目录.
如果-r
是一个没有目录名定;但如果-r
完全不给, grep
默认阅读-
即标准输入 )。
BTW, I would also recommend the ack utility, packaged as the ack-grep
package on Ubuntu or Debian. 顺便说一句,我还建议使用ack实用程序,在Ubuntu或Debian上打包为ack-grep
软件包 。 It does not need any files (default is the source code files under current directory) and it avoids useless non-source files (version control or object files...): 它不需要任何文件(默认是当前目录下的源代码文件),并且避免了无用的非源文件(版本控制或目标文件...):
ack "piece of text"
Also, under emacs , you can use Mx grep
另外,在emacs下,您可以使用Mx grep
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.