Learning shell together (8-2) File Processing
Run the command: xargs ----------------------------------------------- to search for the file with the POSIX_OPEN_MAX symbol.
[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-----------------------------------------------
The argument list too long error may be reported on the top, so no error will be reported when xargs is used.
[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------------------------------------------------
File System space information Df disk space available,
-------------------------------------- [Root @ localhost test] # df-k file system 1 K-block used available % mount point/dev/mapper/VolGroup00-LogVol00 39422564 7808928 29578744 21% // dev/sda1 101086 12623 83244 14%/boottmpfs 271872 0 271872 0%/dev/shm [root @ localhost test] # df-hfile system capacity in use available % mount point/dev/mapper/VolGroup00-LogVol00 38G 7.5G 29G 21% // dev/sda1 99 M 13 M 82 M 14%/boottmpfs 266 M 0 266 M 0%/dev/shm ------------------------------------------------------------------------
Du disk space usage
---------------------------------- [Root @ localhost test] # du/tmp8/tmp/x4/tmp /. ICE-unix4/tmp/keyring-9ed8eo4/tmp /. x11-unix4/tmp/keyring-KdKvoo4/tmp/svbna. tmp4/tmp/keyring-GEGIIR8/tmp/gconfd-root4/tmp/keyring-DGM6mE4/tmp/keyring-vT4uLQ64/tmp [root @ localhost test] # du-s/tmp64/tmp [root @ localhost test] # du-s/ardu: unable to access "/ar": No file or directory [root @ localhost test] # du-s/ardu: unable to access "/ar ": there is no file or directory [root @ localhost test] # du-s/var4602912/var ---------------------------------------------------------
[root@localhost test]# du /tmp8 /tmp/x4 /tmp/.ICE-unix4 /tmp/keyring-9ed8eo4 /tmp/.X11-unix4 /tmp/keyring-KdKvoo4 /tmp/svbna.tmp4 /tmp/keyring-GEGIIR8 /tmp/gconfd-root4 /tmp/keyring-DGM6mE4 /tmp/keyring-vT4uLQ64 /tmp[root@localhost test]# du -s /tmp64 /tmp[root@localhost test]# du -s /ar
Du: cannot access "/ar": No file or directory [root @ localhost test] # du-s/ardu: cannot access "/ar ": there is no such file or directory [root @ localhost test] # du-s/var4602912/var-h, which is more suitable. [Root @ localhost test] # du-h/var200K/var/www/manual/images8.0K/var/www/manual/style/latex .......... .................... 184 K/var/run4.4G/var [root @ localhost test] # du-h-s/var4.4G/var ---------------------------------------------- view/var/all space usage. [Root @ localhost test] # du-s-k/var/* | sort-k1nr 4534260/var/www48696/var/lib15392/var/cache ....... ............... ------------------------------------------------ system quota (quota) comparison file: CMP and DIFF
Compare CMP with [root @ localhost test] # cat onejlksdddnd 'issue [root @ localhost test] # cat comment 'issue daffadsffadfAjkjlj [root @ localhost test] # cmp one twoone two differ: byte 11, line 2 [root @ localhost test] # echo $?
1 # non-zero values are different. DIFF comparison differences
------------------------------------------------[root@localhost test]# diff one two2,9c2,8< d'sdf< sdf< sdf< s< dfs< d< fa< d---> dsdsd'sdf> sdfdsd> sdfdsd> ss123> dfs1231> da daf> fadsf12c11< ---> ajkjlj-----------------------------------------
Use DIFF Convention: use the old file as the first parameter. Different rows are used to place left angle brackets, corresponding to the (first) file on the left, while the front right angle bracket refers to the file on the right. The first two, 9c2, and 8 are the simple expression of the number of the input file line. They indicate the differences and the operations to be edited. c Indicates Change, a increases, and d deletes. Diff output is carefully designed, so other programs can use its output data. For example, the version revision control system uses diff to manage the differences between continuous versions of files. The Patch tool program Path tool program can use the diff output, combined with the original file, to recreate another file, because different parts are usually much smaller than the original file, software developers usually exchange the list of different parts by email, and then use the patch to apply it.
-----------------------------------------------------[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 jlksdddndsdsd'sdfsdfdsdsdfdsdss123dfs1231da daffadsffadfajkjlj[root@localhost test]# diff one two-----------------------------------------
File checksum matching: You can use file checksum to obtain the approximate linear performance. There are many tools available to calculate the file and string checksum, including sum, cksum, the previous checksum, the message digest tool md5 and md5sum, and the security hash algorithm tools sha, shalsum, sha256, and sha384. The instances of Sum are different across different platforms. Cksum is also different on the OSF/1 system. ----------------------------- Compare the md5 value [root @ localhost test] # md5sum onef1ecea4a79a8c4341df35c324e4893ce one ----------------------------- digital signature authentication: Gpg