[root@localhost test]# cat test.sh #!/bin/bash
-n 给所有行加行号
[root@localhost test]# cat -n test 1 #version=DEVEL 2 # System authorization information 3 auth --enableshadow --passalgo=sha512 4 5 # Use CDROM installation media 6 cdrom abc 7 8 # Use graphical install 9 graphical
-b 给非空行加行号
[root@localhost test]# cat -b test 1 #version=DEVEL 2 # System authorization information 3 auth --enableshadow --passalgo=sha512 4 # Use CDROM installation media 5 cdrom abc 6 # Use graphical install 7 graphical
-T 取消制表符 会用^I字符组合去替换文中的所有制表符
[root@localhost test]# cat -T test #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 # Use CDROM installation media cdrom^Iabc # Use graphical install graphical
-A 显示特殊符号
[root@localhost test]# cat -A test #version=DEVEL$ # System authorization information$ auth --enableshadow --passalgo=sha512$ $ # Use CDROM installation media$ cdrom^Iabc$ $ # Use graphical install$ graphical$
向文件追加内容
[root@localhost test]# cat test #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 # Use CDROM installation media cdrom abc # Use graphical install graphical [root@localhost test]# cat >> test <<EOF > testline 1 > testline 2 > EOF [root@localhost test]# cat test #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 # Use CDROM installation media cdrom abc # Use graphical install graphical testline 1 testline 2
覆盖文件内容
[root@localhost test]# cat > test <<EOF > testline 1 > testline 2 > EOF [root@localhost test]# cat test testline 1 testline 2
使用 -EOF左对齐添加的内容
cat <<-EOF Line 1 Line 2 EOF 输出结果为 Line 1 Line 2
其他写法
[root@localhost test]# cat << EOF >>test.sh > ls > EOF
[root@localhost test]# cat test.sh #!/bin/bash ls
使用cat命令的缺陷就是如果文件过大,那么会一闪而过输出所有内容,more命令会显示文本文件的内容,但会在显示每页数据之后停下来
less命令是more的加强版,可以使用更多的前后翻动功能,
原文:https://www.cnblogs.com/zh-dream/p/15196581.html