内容查找
root@uos:~# cat /etc/passwd
root@uos:~# grep root /etc/passwd
这时候我们要将第二个和root关联不大的去掉,我们可以按以下做法:
root@uos:~# grep ^root /etc/passwd
^表示以root为开头。
root@uos:~# grep h /etc/passwd/ 这个是将所有的含有h的内容找出
root@uos:~# grep h$ /etc/passwd
root@uos:~# grep ^# /etc/apache2/apache2.conf(找以#开头的注释文件)
root@uos:~# grep ^$ /etc/apache2/apache2.conf(找空行)
root@uos:~# grep -v ^# /etc/apache2/apache2.conf(找不以#开头的文件)
-v表示取反。
有时候,我们不知道要找的的东西的具体形式
root@uos:~# grep r00t /etc/passwd/
这时候,我们就啥也找不着了,而且有时候我们也不知道自己要找的是大写还是小写的。
root@uos:~# grep Root /etc/ssh/sshd_config
root@uos:~# grep -i root /etc/passwd/
-i表示忽略大小写,直接找出所有关于该样式的内容