linux 命令 cat \/etc\/,一天一个Linux基础命令之查看文件内容cat、tac(示例代码)

cat查看文本文件

1、命令格式cat[OPTION]... [FILE]...

2、命令功能

1.显示文件内容,创建新文件cat>filename

2.输入内容,内容输入完毕之后用Ctrl+D结束输入

3.将几个文件合并为一个文件:cat file1 file2... > file

3、常用参数

-n:在输入数据前面加行号

-b:非空的行输出,并且输出行号

-e|-E:在每行结束后再后面加上$

$一般用于行尾结束

-s:空行不重复输出

-t|-T:换行符显示为^I

4、常用范例

1.查看文件中的内容

命令:cat/etc/issue[[email protected]~]# cat /etc/issue

CentOSrelease 6.5 (Final)

Kernel \ron an \m

[[email protected]~]#

2.将issue中的内容添加到文件尾部

命令:cat /etc/issue >> test[[email protected]~]# cat test

123

123

123

[[email protected]~]# cat /etc/issue >> test

[[email protected]~]# cat test

123

123

123

CentOSrelease 6.5 (Final)

Kernel \ron an \m

[[email protected]~]#

3.显示文件的行数

命令:cat -n test[[email protected]~]# cat -n test

1    123

2    123

3    123

4

5    CentOSrelease 6.5 (Final)

6    Kernel\r on an \m

7

[[email protected]~]#

4.用cat给新文件输入内容cat>file

[[email protected]~]# cat >test1

hello

world

[[email protected]~]# cat test1

hello

world

[[email protected]~]#

提示:用cat输入文件内容时,在文件内容输入完毕时,要用Ctrl+D结束输入

备注:

tac (反向列示)

命令:

tac test1

输出:

说明:tac是将cat反写过来,所以他的功能就跟cat相反,cat是由第一行到最后一行连续显示在萤幕上,而tac则是由最后一行到第一行反向在萤幕上显示出来!

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用以下命令查看/etc中的文件内容: 1. 使用 cat 命令: ``` cat /etc/<file> ``` 例如,要查看 /etc/passwd 文件内容,可以使用以下命令: ``` cat /etc/passwd ``` 2. 使用 tac 命令: ``` tac /etc/<file> ``` tac 命令会将文件内容倒序输出。例如,要倒序查看 /etc/passwd 文件内容,可以使用以下命令: ``` tac /etc/passwd ``` 3. 使用 nl 命令: ``` nl /etc/<file> ``` nl 命令会将文件内容按行号输出。例如,要按行号查看 /etc/passwd 文件内容,可以使用以下命令: ``` nl /etc/passwd ``` 4. 使用 more 命令: ``` more /etc/<file> ``` more 命令会将文件内容按页输出。例如,要分页查看 /etc/passwd 文件内容,可以使用以下命令: ``` more /etc/passwd ``` 5. 使用 less 命令: ``` less /etc/<file> ``` less 命令也会将文件内容按页输出,并且可以使用箭头键和其他按键来滚动和搜索文件内容。例如,要使用 less 命令查看 /etc/passwd 文件内容,可以使用以下命令: ``` less /etc/passwd ``` 6. 使用 head 命令: ``` head /etc/<file> ``` head 命令会将文件的前几行输出。例如,要查看 /etc/passwd 文件的前 10 行内容,可以使用以下命令: ``` head /etc/passwd -n 10 ``` 7. 使用 tail 命令: ``` tail /etc/<file> ``` tail 命令会将文件的后几行输出。例如,要查看 /etc/passwd 文件的后 10 行内容,可以使用以下命令: ``` tail /etc/passwd -n 10 ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值