操作系統: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 ([email protected]) (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.