stat、cut、diff 命令

7.stat命令

stat命令用于查看文件的具体存储信息和时间等信息,格式为“stat 文件名称”。

stat命令可以用于查看文件的存储信息和时间等信息,命令stat anaconda-ks.cfg会显示出文件的三种时间状态(已加粗):Access、Modify、Change。这三种时间的区别将在下面的touch命令中详细详解:

[root@linuxprobe ~]# stat anaconda-ks.cfg
File: ‘anaconda-ks.cfg’
Size: 1213 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 68912908 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:admin_home_t:s0
Access: 2017-07-14 01:46:18.721255659 -0400
Modify: 2017-05-04 15:44:36.916027026 -0400
Change: 2017-05-04 15:44:36.916027026 -0400
Birth: -

8.cut命令

cut命令用于按“列”提取文本字符,格式为“cut [参数] 文本”。

在Linux系统中,如何准确地提取出最想要的数据,这也是我们应该重点学习的内容。一般而言,按基于“行”的方式来提取数据是比较简单的,只需要 设置好要搜索的关键词即可。但是如果按列搜索,不仅要使用-f参数来设置需要看的列数,还需要使用-d参数来设置间隔符号。passwd在保存用户数据信 息时,用户信息的每一项值之间是采用冒号来间隔的,接下来我们使用下述命令尝试提取出passwd文件中的用户名信息,即提取以冒号(:)为间隔符号的第 一列内容:

[root@linuxprobe ~]# head -n 2 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@linuxprobe ~]# cut -d: -f1 /etc/passwd
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
operator
games
ftp
nobody
dbus
polkitd
unbound
colord
usbmuxd
avahi
avahi-autoipd
libstoragemgmt
saslauth
qemu
rpc
rpcuser
nfsnobody
rtkit
radvd
ntp
chrony
abrt
pulse
gdm
gnome-initial-setup
postfix
sshd
tcpdump
linuxprobe

9.diff命令

diff命令用于比较多个文本文件的差异,格式为“diff [参数] 文件”。

在使用diff命令时,不仅可以使用--brief参数来确认两个文件是否不同,还可以使用-c参数来详细比较出多个文件的差异之处,这绝对是判断 文件是否被篡改的有力神器。例如,先使用cat命令分别查看diff_A.txt和diff_B.txt文件的内容,然后进行比较:

[root@linuxprobe ~]# cat diff_A.txt
Welcome to linuxprobe.com
Red Hat certified
Free Linux Lessons
Professional guidance
Linux Course
[root@linuxprobe ~]# cat diff_B.txt
Welcome tooo linuxprobe.com

Red Hat certified
Free Linux LeSSonS
////////.....////////
Professional guidance
Linux Course

接下来使用diff --brief命令显示比较后的结果,判断文件是否相同:

[root@linuxprobe ~]# diff --brief diff_A.txt diff_B.txt
Files diff_A.txt and diff_B.txt differ

最后使用带有-c参数的diff命令来描述文件内容具体的不同:

[root@linuxprobe ~]# diff -c diff_A.txt diff_B.txt
*** diff_A.txt 2017-08-30 18:07:45.230864626 +0800
--- diff_B.txt 2017-08-30 18:08:52.203860389 +0800
***************
*** 1,5 ****
! Welcome to linuxprobe.com
Red Hat certified
! Free Linux Lessons
Professional guidance
Linux Course
--- 1,7 ----
! Welcome tooo linuxprobe.com
!
Red Hat certified
! Free Linux LeSSonS
! ////////.....////////
Professional guidance
Linux Course

猜你喜欢

转载自blog.csdn.net/qq_38570571/article/details/82704035