一起学shell之(八-2)文件处理
一起学shell之(八-2)文件处理
执行命令:xargs
---------------------------------------------
查找以POSIX_OPEN_MAX 符号
[root@localhost test]# grep POSIX_OPEN_MAX /dev/null $(find /usr/include -type f |sort) /usr/include/bits/posix1_lim.h:# define _POSIX_OPEN_MAX 20 /usr/include/bits/posix1_lim.h:# define _POSIX_OPEN_MAX 16 /usr/include/bits/posix1_lim.h:#define _POSIX_FD_SETSIZE _POSIX_OPEN_MAX -----------------------------------------------
上面有可能报argument list too long错误,使用xargs就不会报错。
[root@localhost test]# find /usr/include -type f |xargs grep POSIX_OPEN_MAX /dev/null /usr/include/bits/posix1_lim.h:# define _POSIX_OPEN_MAX 20 /usr/include/bits/posix1_lim.h:# define _POSIX_OPEN_MAX 16 /usr/include/bits/posix1_lim.h:#define _POSIX_FD_SETSIZE _POSIX_OPEN_MAX ------------------------------------------------
文件系统的空间信息
Df 磁盘可用空间,
------------------------------------------ [root@localhost test]# df -k 文件系统 1K-块 已用 可用 已用% 挂载点 /dev/mapper/VolGroup00-LogVol00 39422564 7808928 29578744 21% / /dev/sda1 101086 12623 83244 14% /boot tmpfs 271872 0 271872 0% /dev/shm [root@localhost test]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/VolGroup00-LogVol00 38G 7.5G 29G 21% / /dev/sda1 99M 13M 82M 14% /boot tmpfs 266M 0 266M 0% /dev/shm ------------------------------------------------------------------------
Du 磁盘空间用量
------------------------------------ [root@localhost test]# du /tmp 8 /tmp/x 4 /tmp/.ICE-unix 4 /tmp/keyring-9ed8eo 4 /tmp/.X11-unix 4 /tmp/keyring-KdKvoo 4 /tmp/svbna.tmp 4 /tmp/keyring-GEGIIR 8 /tmp/gconfd-root 4 /tmp/keyring-DGM6mE 4 /tmp/keyring-vT4uLQ 64 /tmp [root@localhost test]# du -s /tmp 64 /tmp [root@localhost test]# du -s /ar du: 无法访问 “/ar”: 没有那个文件或目录 [root@localhost test]# du -s /ar du: 无法访问 “/ar”: 没有那个文件或目录 [root@localhost test]# du -s /var 4602912 /var ---------------------------------------------------------
[root@localhost test]# du /tmp 8 /tmp/x 4 /tmp/.ICE-unix 4 /tmp/keyring-9ed8eo 4 /tmp/.X11-unix 4 /tmp/keyring-KdKvoo 4 /tmp/svbna.tmp 4 /tmp/keyring-GEGIIR 8 /tmp/gconfd-root 4 /tmp/keyring-DGM6mE 4 /tmp/keyring-vT4uLQ 64 /tmp [root@localhost test]# du -s /tmp 64 /tmp [root@localhost test]# du -s /ar
du: 无法访问 “/ar”: 没有那个文件或目录
[root@localhost test]# du -s /ar
du: 无法访问 “/ar”: 没有那个文件或目录
[root@localhost test]# du -s /var
4602912 /var
-h 简易的,更适合。
[root@localhost test]# du -h /var
200K /var/www/manual/images
8.0K /var/www/manual/style/latex
..............................
184K /var/run
4.4G /var
[root@localhost test]# du -h -s /var
4.4G /var
------------------------------------------------
--------------------------------------------------
查看/var/下所有空间使用量。
[root@localhost test]# du -s -k /var/* |sort -k1nr
4534260 /var/www
48696 /var/lib
15392 /var/cache
......................
--------------------------------------------------
系统配额(quota)
比较文件:
CMP与DIFF
---------------------------------- CMP对比 [root@localhost test]# cat one jlksdddn d'sdf sdf sdf s dfs d fa d fa df [root@localhost test]# cat two jlksdddn dsdsd'sdf sdfdsd sdfdsd ss123 dfs1231 da daf fadsf fa df Ajkjlj [root@localhost test]# cmp one two one two differ: byte 11, line 2 [root@localhost test]# echo $?
1 #非零为有不同。
DIFF比较不同之处
------------------------------------------------ [root@localhost test]# diff one two 2,9c2,8 < d'sdf < sdf < sdf < s < dfs < d < fa < d --- > dsdsd'sdf > sdfdsd > sdfdsd > ss123 > dfs1231 > da daf > fadsf 12c11 < --- > ajkjlj -----------------------------------------
使用DIFF惯例:将旧文件作为第一个参数。
不同的行会以前置左角括号的方式,对应到左边的(第一个)文件,而前置右角括号则指的是右边的文件。最前面的2,9c2,8为输入文件行编号的简洁表示方式,指出不同之处以及需要编辑的操作,c表示改变,a增加,d册除的意思。
Diff的输出是仔细设计过的,因此其它程序可使用它的输出数据,例如版本修订控制系统就使用diff管理文件连续版本之间的差异。
Patch工具程序
Path工具程序可利用diff的输出,结合原始文件,以重建另一个文件,因为相异的部分,通常比原始文件小很多,软件开发人员常会通过email交换相异处的列表,再使用patch应用它。
----------------------------------------------------- [root@localhost test]# diff -c one two >test.dif [root@localhost test]# cat test.dif *** one 2012-05-24 19:17:59.000000000 +0800 --- two 2012-05-24 19:18:37.000000000 +0800 *************** *** 1,12 **** jlksdddn ! d'sdf ! sdf ! sdf ! s ! dfs ! d ! fa ! d fa df ! --- 1,11 ---- jlksdddn ! dsdsd'sdf ! sdfdsd ! sdfdsd ! ss123 ! dfs1231 ! da daf ! fadsf fa df ! ajkjlj [root@localhost test]# patch < test.dif patching file one [root@localhost test]# cat one jlksdddn dsdsd'sdf sdfdsd sdfdsd ss123 dfs1231 da daf fadsf fa df ajkjlj [root@localhost test]# diff one two -----------------------------------------
文件校验和匹配:
可以使用file checksum取得近似线性的性能,有很多工具可用来计算文件与字符串的校验和,包括sum、cksum,以前checksum,消息摘要工具md5与md5sum,安全性散列算法工具sha、shalsum、sha256以及sha384。Sum的实例在各平台间都不相同。Cksum在OSF/1系统上也不相同。
-------------------------------
比较md5值
[root@localhost test]# md5sum one
f1ecea4a79a8c4341df35c324e4893ce one
-------------------------------
数字签名认证:
Gpg
评论暂时关闭