文本文件查看命令:
cat , tac , head , tail , more , less ; stat ; touch ;
分屏查看
[root@localhost ~]# cat -n /etc/rc.d/init.d/functions ......... 671 672 # A sed expression to filter out the files that is_ignored_file recognizes 673 __sed_discard_ignored_files='/\(~\|\.bak\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d' 674 675 if [ "$_use_systemctl" = "1" ]; then 676 if [ "x$1" = xstart -o \ 677 "x$1" = xstop -o \ 678 "x$1" = xrestart -o \ 679 "x$1" = xreload -o \ 680 "x$1" = xtry-restart -o \ 681 "x$1" = xforce-reload -o \ 682 "x$1" = xcondrestart ] ; then 683 684 systemctl_redirect $0 $1 685 exit $? 686 fi 687 fi 688 689 strstr "$(cat /proc/cmdline)" "rc.debug" && set -x 690 return 0 691 [root@localhost ~]#
more – file perusal filter for crt viewing
more [options] file […]
特点:翻屏至尾部后自动退出;
less – opposite of more
head – output the first part of files
head [OPTION]… [FILE]…
OPTION:
-n NUMBER : 显示头部多少行;
-NUMBER : 同上;
默认显示头部开始的10行内容:
[root@localhost ~]# head /etc/rc.d/init.d/functions # -*-Shell-script-*- # # functions This file contains functions to be used by most or all # shell scripts in the /etc/init.d directory. # TEXTDOMAIN=initscripts # Make sure umask is sane umask 022
显示头部开始的5行内容:
[root@localhost ~]# head -n 5 /etc/rc.d/init.d/functions # -*-Shell-script-*- # # functions This file contains functions to be used by most or all # shell scripts in the /etc/init.d directory. # [root@localhost ~]# head -5 /etc/rc.d/init.d/functions # -*-Shell-script-*- # # functions This file contains functions to be used by most or all # shell scripts in the /etc/init.d directory. # [root@localhost ~]#
tail – output the last part of files
tail [OPTION]… [FILE]…
OPTION:
-n NUMBER : 显示头部多少行;
-NUMBER : 同上;
-f : 查看文件尾部内容结束后不退出,跟随显示新增的信息;有监视效果,比如用来监视日志文件;按 Crtl + c 退出;
默认显示倒数10行内容:
[root@localhost ~]# tail /etc/rc.d/init.d/functions "x$1" = xcondrestart ] ; then systemctl_redirect $0 $1 exit $? fi fi strstr "$(cat /proc/cmdline)" "rc.debug" && set -x return 0
指定显示倒数5行内容:
[root@localhost ~]# tail -n 5 /etc/rc.d/init.d/functions fi strstr "$(cat /proc/cmdline)" "rc.debug" && set -x return 0 [root@localhost ~]# tail -5 /etc/rc.d/init.d/functions fi strstr "$(cat /proc/cmdline)" "rc.debug" && set -x return 0 [root@localhost ~]#
stat – display file or file system status , 查看文件或文件系统的状态;
stat [OPTION]… FILE…
[root@localhost ~]# stat /etc/rc.d/init.d/functions File: ‘/etc/rc.d/init.d/functions’ Size: 17500 Blocks: 40 IO Block: 4096 regular file Device: fd00h/64768d Inode: 33689945 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: system_u:object_r:bin_t:s0 Access: 2018-03-18 10:42:13.330017017 +0800 Modify: 2017-05-03 18:17:50.000000000 +0800 Change: 2017-12-27 05:38:27.428006508 +0800 Birth: - [root@localhost ~]#
文件有2类数据:
> 元数据 : metadata
> 数据 : data
时间戳:
Access: 2018-03-18 10:42:13.330017017 +0800
Modify: 2017-05-03 18:17:50.000000000 +0800
Change: 2017-12-27 05:38:27.428006508 +0800
Access time : 最近的访问时间,centos 7 系统上,对于频繁访问的文件,短时间点连续访问的文件,此时间不会变动,这跟系统性能需求有关;
Modify time : 最近的更改时间,更改的对象是数据;
Change time : 最近的改动时间,改动的是元数据; 当数据更改后,此时间也会变动;
touch – change file timestamps
touch [OPTION]… FILE…
OPTION:
-c : 指定文件路径不存在时不予创建;
-a : 仅修改 Access time ;
-m : 仅修改 Modify time ;
-t STAMP : STAMP 的格式为 [[CC]YY]MMDDhhmm[.ss] ;指定时间;可分别与 -a -m 组合使用;
创建一个文件,并查看文件状态:
[root@localhost ~]# touch abc [root@localhost ~]# stat abc File: ‘abc’ Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 67727508 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2018-03-18 16:47:59.510729045 +0800 Modify: 2018-03-18 16:47:59.510729045 +0800 Change: 2018-03-18 16:47:59.510729045 +0800 Birth: -
再次使用 touch 命令去创建已有的文件,并查看文件状态,发现文件的3个时间都发生变化:
[root@localhost ~]# touch abc [root@localhost ~]# [root@localhost ~]# stat abc File: ‘abc’ Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 67727508 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2018-03-18 16:48:09.492729824 +0800 Modify: 2018-03-18 16:48:09.492729824 +0800 Change: 2018-03-18 16:48:09.492729824 +0800 Birth: -
使用 cat 命令查看文件内容,发现只有文件的 Access time 发生变化:
[root@localhost ~]# cat abc [root@localhost ~]# [root@localhost ~]# stat abc File: ‘abc’ Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 67727508 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2018-03-18 16:48:30.920731496 +0800 Modify: 2018-03-18 16:48:09.492729824 +0800 Change: 2018-03-18 16:48:09.492729824 +0800 Birth: -
再次使用 cat 访问文件,发现3个时间都未发生变化:
[root@localhost ~]# cat abc [root@localhost ~]# stat abc File: ‘abc’ Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 67727508 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2018-03-18 16:48:30.920731496 +0800 Modify: 2018-03-18 16:48:09.492729824 +0800 Change: 2018-03-18 16:48:09.492729824 +0800 Birth: - [root@localhost ~]#
使用 -t 选项指定文件的 Modify time , 发现文件的 Change time 也跟着变化,改为系统当前的时间;
[root@localhost ~]# touch -m -t 201710251133.45 abc [root@localhost ~]# [root@localhost ~]# stat abc File: ‘abc’ Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 67727508 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2018-03-18 16:48:30.920731496 +0800 Modify: 2017-10-25 11:33:45.000000000 +0800 Change: 2018-03-18 17:08:43.670826103 +0800 Birth: -
同理,指定更改文件的 Access time , 发现文件的 Change time 更改为系统当前时间;
[root@localhost ~]# touch -a -t 201609060512.44 abc [root@localhost ~]# [root@localhost ~]# stat abc File: ‘abc’ Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 67727508 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2016-09-06 05:12:44.000000000 +0800 Modify: 2017-10-25 11:33:45.000000000 +0800 Change: 2018-03-18 17:12:32.638843964 +0800 Birth: - [root@localhost ~]#