grep -r和-R有什么区别 [英] What's the difference between grep -r and -R

查看:6884
本文介绍了grep -r和-R有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在手册页中:

-r

以符号形式递归地读取每个目录下的所有文件 仅当它们在命令行上时才会链接.

Read all files under each directory, recursively, following symbolic links only if they are on the command line.

在命令行上"到底是什么意思?

what exactly does "being on the command line" means?

谢谢.

推荐答案

在命令行中"引用传递给grep的参数.如果您将符号链接作为 argument 作为grep -r的链接,则会跟随它.但是,如果grep -r遍历目录时遇到grep -r符号链接,则它不会跟随该目录(与grep -R相反).

"Being on the command line" refers to the arguments passed to grep. If you give a symbolic link as an argument to grep -r it follows it. However, if grep -r encounters a symbolic link while traversing a directory it does not follow it (in contrast to grep -R which does).

想象一下,您有一个包含一堆文件的目录,其中包括一个包含指向..(父目录)的符号链接的文件:

Imagine you have a directory with a bunch of files in it, including one containing a symbolic link to .. (the parent directory):

$ ls -la
total 0
drwxr-xr-x 2 aw aw 47 Mar 31 16:05 .
drwxr-xr-x 3 aw aw 27 Mar 31 16:04 ..
-rw-r--r-- 1 aw aw  0 Mar 31 16:05 bar
-rw-r--r-- 1 aw aw  0 Mar 31 16:05 baz
lrwxrwxrwx 1 aw aw  2 Mar 31 16:04 foo -> ..
-rw-r--r-- 1 aw aw  0 Mar 31 16:05 quux
$

然后

  • grep -r foobar .将仅grep此目录中的文件,
  • grep -r foobar foo将grep父目录(..)中的文件(遵循作为参数给出的符号链接),
  • grep -R foobar .还将grep父目录中的文件(紧跟在作为当前参数但在遍历当前目录时找到的符号链接 not 后面).
  • grep -r foobar . will only grep the files inside this directory,
  • grep -r foobar foo will grep the files in the parent directory (..) (following the symlink given as an argument),
  • grep -R foobar . will also grep the files in the parent directory (following the symlink not given as an argument but found while traversing the current directory).

这篇关于grep -r和-R有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆