您的位置:首页 > 运维架构 > Linux

Linux命令查看文件内容

2018-09-01 16:20 751 查看

操作系统:CentOS 7.0

head、tail、cat命令主要用于查看文件内容,head是查看文件前的内容,tail命令是查看文件末尾内容,cat命令主要用于查看文件内容。

[sky9890@localhost tmp]$ head -10 /var/log/messages

head: 无法打开"/var/log/messages" 读取数据: 权限不够

[sky9890@localhost tmp]$ su     #切换到root

密码:

[root@localhost tmp]# head -10 /var/log/messages  #查看文件前10行

Aug  9 09:40:44 localhost journal: Runtime journal is using 6.1M (max allowed 49.1M, trying to leave 73.7M free of 485.4M available → current limit 49.1M).

Aug  9 09:40:44 localhost kernel: Initializing cgroup subsys cpuset

Aug  9 09:40:44 localhost kernel: Initializing cgroup subsys cpu

Aug  9 09:40:44 localhost kernel: Initializing cgroup subsys cpuacct

Aug  9 09:40:44 localhost kernel: Linux version 3.10.0-862.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Fri Apr 20 16:44:24 UTC 2018

Aug  9 09:40:44 localhost kernel: Command line: BOOT_IMAGE=/vmlinuz-3.10.0-862.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet.UTF-8

Aug  9 09:40:44 localhost kernel: Disabled fast string operations

Aug  9 09:40:44 localhost kernel: e820: BIOS-provided physical RAM map:

Aug  9 09:40:44 localhost kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009efff] usable

Aug  9 09:40:44 localhost kernel: BIOS-e820: [mem 0x000000000009f000-0x000000000009ffff] reserved

[sky9890@localhost tmp]$ tail -fn 5 /var/log/messages  

tail: 无法打开"/var/log/messages" 读取数据: 权限不够

tail: 没有剩余文件

[sky9890@localhost tmp]$ su  #切换到root

密码:

[root@localhost tmp]# tail -fn 5  /var/log/messages  #查看文件末尾5行,按ctrl+z结束 

Sep  1 15:44:09 localhost dhclient[832]: bound to 192.168.153.128 -- renewal in 709 seconds.

Sep  1 15:44:09 localhost dbus[644]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'

Sep  1 15:44:09 localhost systemd: Started Network Manager Script Dispatcher Service.

Sep  1 15:44:09 localhost nm-dispatcher: req:1 'dhcp4-change' [eth0]: new request (3 scripts)

Sep  1 15:44:09 localhost nm-dispatcher: req:1 'dhcp4-change' [eth0]: start running ordered scripts...

[root@localhost /]# cat  /tmp/test.txt  #查看文件内容

My name is WuHaiMing

I am  From Ping Xiang.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  head tail cat