文件内容查看

1.使用cat命令查看文件内容

[test@localhost ~]$ mkdir dir1
[test@localhost ~]$ cd dir1
[test@localhost dir1]$ cat file1
welcome
abc
def
ghi

2.使用nl命令计算文件中行号

(1)用nl命令列出文件的全部内容,包括行号,但空白行不加行号

ghi
[test@localhost dir1]$ nl file1
     1	welcome
     2	abc
     3	def
     4	ghi

(2)用nl命令的参数b列出file1的内容,空白行也加上行号

[test@localhost dir1]$ nl -b a file1
     1	welcome
     2	abc
     3	def
     4	ghi
     5	
     6	jkl

(3)使行号面前自动补上0,统一输出格式,行号前默认补0

[test@localhost dir1]$ nl -b a -n rz file1
000001	welcome
000002	abc
000003	def
000004	ghi
000005	
000006	jkl

(4)行号前按设置位数补0

[test@localhost dir1]$ nl -b a -n rz -w 3 file1
001	welcome
002	abc
003	def
004	ghi
005	
006	jkl

3.使用more命令分页查看文件内容

(1)以分页的方式查看文件名file1的内容

[test@localhost dir1]$ more file1
welcome
abc
def
ghi

jkl
[test@localhost dir1]$ cat file1
welcome
abc
def
ghi

jkl

(2)分页查看install.log文件,使用Q键退出查看

[test@localhost dir1]$ mkdir root
[test@localhost dir1]$ ls
file1  root
[test@localhost dir1]$ ll
总用量 4
-rw-r--r--. 1 test test 25 3月  25 19:35 file1
drwxrwxr-x. 2 test test  6 3月  25 19:57 root
[test@localhost dir1]$ more /home/test/dir1/root/install.log
Installing setup-2.5.58-7.el.noarch
Installing setup-2.5.58-7.el.noarch
Installing setup-2.5.58-7.el.noarch
Installing setup-2.5.58-7.el.noarch
Installing setup-2.5.58-7.el.noarch
Installing setup-2.5.58-7.el.noarch
Installing setup-2.5.58-7.el.noarch
Installing setup-2.5.58-7.el.noarch
Installing setup-2.5.58-7.el.noarch
Installing setup-2.5.58-7.el.noarch

4.使用less命令查看文件file1的内容

[test@localhost dir1]$ less file1

输入‘Q’退出

5.使用head命令查看文件内容

[test@localhost dir1]$ mkdir etc
[test@localhost dir1]$ ls
etc  file1  root
[test@localhost dir1]$ touch passwd
[test@localhost dir1]$ head -5 /home/test/dir1/etc/passwd
root:x:0:0:root:/root/:/bin/bash

 6.使用tail命令查看文件内容

[test@localhost dir1]$ tail -5 /home/test/dir1/etc/passwd
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值