Linux basic commands (2)-"Six ways to view the contents of a file"

View file content


1. cat

用法:cat [选项]...[文件]...
选项:
  -n  显示行号,包括空白行
  -b  显示行号,空白行不显示行号

eg:

[root@qll ~]# cat /etc/passwd
[root@qll ~]# cat -n /etc/passwd
[root@qll ~]# cat -b /etc/passwd


2. more

The more command has the same function as cat to view the content of the file, but the difference is that more can view the content of the file by page, and it also supports functions such as direct jump lines.

Enter键:向下n行,需要定义。默认为1行

空格键:向下滚动一屏

Ctrl+B:返回上一屏

= 输出当前行的行号

V 调用vi编辑器

!命令 调用Shell,并执行命令

q 退出more

eg:

[root@qll ~]# more /var/log/messages


3. less

描述:分页查看文件内容,
操作:
空格(下一页)
方向键(上下回翻)
q键(退出查看)

eg:

[root@qll ~]# less /var/log/mingongge.log


4. head

用法:head [选项]...[文件]...
选项:
  -c nK  显示文件前nKB的内容。
  -n     显示文件前n行的内容。

eg:

[root@qll ~]# head -c 2k /var/log/messages#View the content of the first 2KB of the file
[root@qll ~]# head -n 15 /var/log/messages#View the content of the first 15 lines of the file


5. tail

用法:tail [选项]...[文件]...
选项:
  -c nK  显示文件末尾nKB的内容。
  -n     显示文件末尾n行的内容。
  -f     动态显示文件内容,常用于查看日志,按 Ctrl+C 组合键退出。

eg:

[root@qll ~]# tail -c 2KB /var/log/messages#View the content of the 2KB at the end of the file#View the content of the
[root@qll ~]# tail -n 15 /var/log/messages15 lines at the end of the file#View the content of the
[root@qll ~]# tail -f /var/log/messagesfile dynamically in real time


6. grep

用法:grep [选项] 匹配模式 [文件]...
常用选项:
  -i  忽略大小写。
  -v  取反匹配
  

eg:

[root@qll ~]# grep root /etc/passwd#Filter out rootthe lines contained in the passwd file .
[root@qll ~]# grep -i ROOT /etc/passwd#Filter out the included ROOTlines (not case sensitive)
[root@qll ~]# grep -v root /etc/passwd#Filter out rootthe lines that are not included .

Guess you like

Origin blog.csdn.net/qq_47354826/article/details/114004616