cat、more、less命令

cat命令查看文件内容

[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

more命令

使用cat命令的缺陷就是如果文件过大,那么会一闪而过输出所有内容,more命令会显示文本文件的内容,但会在显示每页数据之后停下来

more命令的翻页功能:

  • 空格键(Space):代表向下翻一页。
  • f:向下翻一页
  • Enter:代表向下滚动一行。
  • /字符串:代表在当前显示的内容中,向下查找“字符串”这个关键字。
  • :f:立刻显示出文件名与当前的行号。
  • q:代表立即退出,不予显示。
  • b或[ctrl]-b:往回翻,不过该操作只对文件有用。

less命令

less命令是more的加强版,可以使用更多的前后翻动功能,

  • s:下翻半屏
  • f: 下翻一屏
  • b:上翻一屏
  • u:上翻半屏
  • d:下翻半屏
  • j: 下翻一行
  • k:上翻一行
原文地址:https://www.cnblogs.com/zh-dream/p/15196581.html