shell脚本——比较两个文件大小、权限

xiaoxiao2021-02-28  125

#!/bin/bash #创建文件/usr/local/1.txt、/etc/local/2.txt,分别给权限655、712 #文件的字节数 、字数、行数 wc  /usr/local/1.txt >aa.txt wc  /etc/local/2.txt >bb.txt #文件的大小 du -h  --max-depth=2 /usr/local/1.txt >>aa.txt du -h  --max-depth=2 /etc/local/2.txt >>bb.txt #文件的权限 stat  /usr/local/1.txt |grep Access | awk '{print $2}' >>aa.txt stat  /etc/local/2.txt |grep Access | awk '{print $2}' >>bb.txt #文件最后修改时间 stat /usr/local/1.txt | grep Modify | awk '{split($3,var,".");print var [1]}' >>aa.txt stat /etc/local/2.txt | grep Modify | awk '{split($3,var,".");print var [1]}' >>bb.txt #比较文件aa.txt与文件bb.txt,确定文件1.txt与文件2.txt的大小、权限、修改时 间 diff aa.txt bb.txt #列出两个aa.txt与bb.txt的内容比较 CurRow=1 LastRow=`cat aa.txt | wc -l`     while [ $CurRow -le $LastRow ] do       for x in `awk 'NR=='$CurRow' {print $0}' aa.txt`     do         for y in `awk 'NR=='$CurRow' {print $0}' bb.txt`             do         if [ "$x" == "$y" ];then           echo "$x" >>result.txt         fi         done      done      ((CurRow++)) done   在result.txt文件中,保存了两个文件大小,时间的相同性质。
转载请注明原文地址: https://www.6miu.com/read-39551.html

最新回复(0)