cat命令用于查看纯文本文件(内容较少的),格式为“cat [选项] [文件]”
由第一行开始显示文件内容
[root@centtos7 ~]# cat /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
...
可以输入-n参数显示行数:
[root@centtos7 ~]# cat -n /etc/profile
1 # /etc/profile
2
3 # System wide environment and startup programs, for login setup
4 # Functions and aliases go in /etc/bashrc
5
6 # It's NOT a good idea to change this file unless you know what you
7 # are doing. It's much better to create a custom.sh shell script in
8 # /etc/profile.d/ to make custom changes to your environment, as this
9 # will prevent the need for merging in future updates.
使用管道符进行翻页显示:
[root@centtos7 ~]# cat -n /etc/profile | more
会出现翻页提示more,按住回车读取下一行,按住空格读取下一页:

more命令用于查看纯文本文件(内容较多的),格式为“more [选项] 文件”
一页一页翻动显示文件
[root@www ~]# more /etc/man_db.config
#
# Generated automatically from man.conf.in by the
# configure script.
#
# man.conf from man-1.6d
....(中间省略)....
--More--(28%) <== 重点在这一行喔!你的光标也会在这里等待你的命令
在 more 这个程序的运行过程中,你有几个按键可以按的:
less 与 more 类似,但是比 more 更好的是,他可以往前翻页!
less在显示文件内容的时候,不是加载所有文件内容之后才显示,而是根据显示加载需要的内容,因此在查看超大文件时有较高的效率
less /etc/profile
less运行时可以输入的命令有:
取出文件前面几行
选项与参数:
例如:取出文件的前10行:
[root@centtos7 ~]# head -10 /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
取出文件后面几行
tail命令最强悍的功能是-f参数可以持续刷新一个文件的内容,当想要实时查看最新日志文件时,这特别有用
选项与参数:
[ctrl]+c才会结束tail的侦测[root@centtos7 ~]# tail /etc/profile
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
tr命令用于替换文本文件中的字符,格式为“tr [原始字符] [目标字符]”
在很多时候,我们想要快速地替换文本中的一些词汇,又或者把整个文本内容都进行替换,如果进行手工替换,难免工作量太大。这时,就可以先使用cat命令读取待处理的文本,然后通过管道符把这些文本内容传递给tr命令进行替换操作即可。
例如,把某个文本内容中的英文全部替换为大写:🙌
[root@centtos7 dahe]# cat hello.txt | tr [a-z] [A-Z]
HELLO WORLD
HELLO WORLD
1234567890
!!!
wc命令用于统计指定文本的行数、字数、字节数,格式为“wc [参数] 文本”

案例:如下,这三个值分别是行数,单词数,字节数:
[root@centtos7 dahe]# wc hello.txt
4 6 39 hello.txt
stat命令用于查看文件的具体存储信息和时间等信息,格式为“stat 文件名称”
[root@centtos7 dahe]# stat hello.txt
File: ‘hello.txt’
Size: 39 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 1611614528 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:default_t:s0
Access: 2022-10-04 06:18:35.383430370 -0400
Modify: 2022-10-04 06:18:31.049425015 -0400
Change: 2022-10-04 06:18:31.051425017 -0400
Birth: -
cut命令用于按“列”提取文本字符,格式为“cut [参数] 文本”
我们使用下述命令尝试提取出passwd文件中的用户名信息:
如果按列搜索,不仅要使用
-f参数来设置需要看的列数,还需要使用-d参数来设置间隔符号🥭
[root@centtos7 dahe]# cut -d: -f1 /etc/passwd
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
operator
games
ftp
nobody
...
diff命令用于比较多个文本文件的差异,格式为“diff [参数] 文件”
在使用diff命令时,不仅可以使用--brief参数来确认两个文件是否不同,还可以使用-c参数来详细比较出多个文件的差异之处,这绝对是判断文件是否被篡改的有力神器
使用diff --brief命令显示比较后的结果,判断文件是否相同:
[root@centtos7 dahe]# diff --brief hello.txt ni.txt
Files hello.txt and ni.txt differ
使用带有-c参数的diff命令来描述文件内容具体的不同:
[root@centtos7 dahe]# diff -c hello.txt ni.txt
*** hello.txt 2022-10-04 06:18:31.049425015 -0400
--- ni.txt 2022-10-04 06:39:24.889943617 -0400
***************
*** 1,4 ****
! hello world
! HELLO WORLD
! 1234567890
! !!!
--- 1 ----
! nihaoa