我是 Linux 新手。当我输入 grep filename
并按下 enter 时,它显示了一个带光标的空行,我不得不按下 ctrl+z 或 ctrl+c 退出。它不应该向我显示命令不完整的某种错误吗?简而言之,我输入 grep filename
并按下 enter 后发生了什么。
最佳答案
当您键入 grep test1
时,test1
不是文件名,而是您正在搜索的模式,您的输入文件是 stdin
。因此,您的控制台输入将是您的“输入文件”。您可以看到,当您输入包含字符串“test1”的行时,在这种情况下,模式匹配并立即在控制台上再次打印出来。
参见 here对于它的手册页
grep searches the named input FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name)
关于具有存在文件名的linux grep命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38288303/