linux的文本文件,Linux查看文本文件

less

less程序可以查看一个文本文件的内容:

$ less .bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.

# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)

# for examples

# If not running interactively, don't do anything

case $- in

*i*) ;;

*) return;;

esac

# 省略

上面的例子使用less程序查看了.bashrc文件的内容。

常用的操作如下:

操作

功能

空格键

向下翻页

按键 pagedown

向下翻页

按键 pageup

向上翻页

/string

向下搜索string

?string

向上搜索string

n

搜索下一个

N

搜索上一个

q

离开less

cat

cat命令也可以查看文本文件内容,它的功能很多,下面是一些常见的:

-A:显示特殊字符。

-n:显示行号。

-b:仅对非空白行显示行号。

下面使用cat查看文件.bashrc内容:

$ cat .bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.

# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)

# for examples

# 省略

使用-n选项查看行号:

$ cat -n .bashrc

1 # ~/.bashrc: executed by bash(1) for non-login shells.

2 # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)

3 # for examples

4

5 # If not running interactively, don't do anything

6 case $- in

7 *i*) ;;

8 *) return;;

9 esac

# 省略

使用-b仅对非空白行显示行号:

$ cat -b .bashrc

1 # ~/.bashrc: executed by bash(1) for non-login shells.

2 # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)

3 # for examples

4 # If not running interactively, don't do anything

5 case $- in

6 *i*) ;;

7 *) return;;

8 esac

# 省略

-A选项可以在文档中将Tab用^I显示,将断行符号用$显示:

$ cat -A .bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.$

# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)$

# for examples$

$

# If not running interactively, don't do anything$

case $- in$

*i*) ;;$

*) return;;$

esac$

可以看到,每行的最后都有断行符号$。

head tail

head命令显示文档的“头”,tail命令显示文档的“尾”。

使用head显示文档的前5行:

$ head -n 5 .bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.

# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)

# for examples

# If not running interactively, don't do anything

$

使用tail显示文档的最后5行:

$ tail -n 5 .bashrc

. /usr/share/bash-completion/bash_completion

elif [ -f /etc/bash_completion ]; then

. /etc/bash_completion

fi

fi

$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值