第一部分

文件的时间信息 (修改时间)
       atime   访问时间
       mtime   修改时间
   ctime   改变时间(文件属性)

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

date
       find -mtime 按天查找数据
            -mmin   

    利用find找出文件之后, 进行批量处理:
  1) 批量删除
  find /oldboy_dir/ -type f -mtime -1|xargs rm -f

有疑问???????????????????????????????????????????

 [root@localhost opt]# find /opt -type f -mtime +1 ###从现在开始算,1天以前的所有文件
 [root@localhost opt]# find /opt -type f -mtime -1 ###昨天到现在已经创建的文件
 /opt/world.sql
 /opt/haha.cnf
 /opt/my.cnf.bak
 /opt/123.txt
 [root@localhost opt]# find /opt/ -type f -mtime 1 ### 昨天一天创建的所有文件
 /opt/world.sql
 /opt/haha.cnf
 /opt/my.cnf.bak
 [root@localhost opt]# find /opt/ -type f -mtime 0 ###昨天现在到今天现在已经创建的文件
 /opt/123.txt
 

第二部分

 

批量删除

 [root@localhost opt]# find /opt/ -type f -mtime -1|xargs ###通过xargs重新排列成一行
 /opt/test/asd.txt /opt/123.txt
 [root@localhost opt]# find /opt/ -type f -mtime -1|xargs rm -rf
 [root@localhost opt]# find /opt/ -type f -mtime -1
 

标准输入输出

 [root@localhost test]# xargs -n5 <test01.txt
 01 02 03 04 05
 06 07 08 09 10
 [root@localhost test]# xargs -n10 <test01.txt
 01 02 03 04 05 06 07 08 09 10

系统符号信息

  $ 
  a 调取变量信息
  b 区分用户类型 $ 区分普通用户和root用户
  c 结合awk对文件进行取列

$变量

 [root@localhost test]# nsh=123
 [root@localhost test]# echo $nsh
 123

对awk去列

 [root@localhost test]# xargs -n 2 <test01.txt
 01 02
 03 04
 05 06
 07 08
 09 10
 [root@localhost test]# xargs -n 2 <test01.txt |awk '{print $2}'
 02
 04
 06
 08
 10
 [root@localhost test]# xargs -n 2 <test01.txt |awk '{print $1}'
 01
 03
 05
 07
 09
 [root@localhost test]# xargs -n 2 <test01.txt |awk '{print $0}'
 01 02
 03 04
 05 06
 07 08
 09 10
 

 

 
  a 强制的作用 wq!
  b 可以实现取反

 

 [root@localhost test]# cat test02.txt
 oldboy01
 oldboy02
 oldboy03
 oldgirl01
 oldboy04
 [root@localhost test]# grep "oldgirl" test02.txt
 oldgirl01
 [root@localhost test]# grep -v "oldgirl" test02.txt
 oldboy01
 oldboy02
 oldboy03
 oldboy04
 [root@localhost test]# awk '/oldgirl/' test02.txt
 oldgirl01
 [root@localhost test]# awk '!/oldgirl/' test02.txt
 oldboy01
 oldboy02
 oldboy03
 oldboy04
 

 

 [root@localhost opt]# cd test/
 [root@localhost test]# mkdir page
 [root@localhost test]# ll
 total 16
 drwxr-xr-x. 2 root root 6 Apr 24 05:58 page
 -rw-r--r--. 1 root root 30 Apr 24 05:45 test01.txt
 -rw-r--r--. 1 root root 46 Apr 24 05:52 test02.txt
 -rw-r--r--. 1 root root 10 Apr 24 05:12 test03.txt
 -rw-r--r--. 1 root root 10 Apr 24 05:12 test04.txt
 [root@localhost test]# cd ..
 [root@localhost opt]# find test/ -type f ###查询当前test目录下的文件
 test/test03.txt
 test/test04.txt
 test/test01.txt
 test/test02.txt
 [root@localhost opt]# find test/ ! -type f ###查询test目录下的非文件
 test/
 test/page
 

!信息  可以快速调取执行历史命令(慎用)

 [root@localhost opt]# find test/ ! -type f
 test/
 test/page
 [root@localhost opt]# !find ###执行上述命令
 find test/ ! -type f
 test/
 test/page
 

实现管道功能
     将前一个命令执行的结果交给管道后面的命令进行处理
一般管道符号 会经常和xargs命令配合使用
批量删除操作

 find /test -type f -name "test*.txt"|xargs rm
 find /test/ -type f -delete
 find /test/ -type f -exec rm -f {} \;

         批量复制

 find /test -type f -name "test*.txt" |xargs -i cp {} /oldgirl/
 find /test -type f -name "test*.txt" |xargs cp -t /oldgirl/
 find /test -type f -name "test*.txt" -exec cp -a {} /oldgirl \;

        批量移动

 find zhangsan/ -name "test*.txt" |xargs mv -t lisi/
 find lisi/ -name "test*.txt" |xargs -i mv {} zhangsan/
 find zhangsan/ -name "test*.txt" -exec mv {} lisi/ \;

 

双引号,单引号,$符号的区别

 [root@localhost test]# echo '`123`'
 `123`
 [root@localhost test]# echo '`echo 123`'
 `echo 123`
 [root@localhost test]# echo "`echo 123`"
 123
 [root@localhost test]# echo "$(echo 123)"
 123
 ``等价于$()

重定向

    >/1>   标准输出重定向符号
  >>/1>> 标准输出追加重定向符号
  2> 错误输出重定向符号
  2>> 错误输出追加重定向符号

示例一

 [root@localhost test]# cat >> wangwu<<eof
 > zhangsan
 > zhangsan
 > eof
 [root@localhost test]# cat wangwu
 zhangsan
 zhangsan
 [root@localhost test]# ls
 lisi wangwu zhangsan
 [root@localhost test]# cat >>wangwu<<lisi
 > askjjsfs
 > rgjfhgfh
 > cbvfgh
 > lisi
 [root@localhost test]# cat wangwu
 zhangsan
 zhangsan
 askjjsfs
 rgjfhgfh
 cbvfgh

示例二

 [root@localhost test]# echo 123>haha
 [root@localhost test]# echo 123 >haha
 [root@localhost test]# cat haha
 123
 [root@localhost test]# ll
 total 8
 -rw-r--r--. 1 root root 4 Apr 24 23:59 haha
 [root@localhost test]# echo sdfjs>>haha
 [root@localhost test]# cat haha
 123
 sdfjs
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄