zoukankan      html  css  js  c++  java
  • find查找到并删除,替换指定文件

    1、删除/root/work/tomcat/logs/目录下,所有目录。

    find /root/work/tomcat/logs/* -type d | xargs rm -rf

    顺便列一下find的相关使用

    2、删除/root/work/tomcat/logs/目录下,所有文件。

    find /root/work/tomcat/logs/* -type f | xargs rm -rf

    3、将/usr/local/backups目录下所有10天前带"."的文件删除

    find /usr/local/backups -mtime +10 -name "*.*" -exec rm -rf {} ;

    -type f  查找文件
    -type d 查找目录

    -mtime -2 修改时间在2天内
    -mtime +3 修改时间在3天前
    -exec rm {} ;   将找到的文件 (假定找到文件的名字为 a.txt), 执行 rm a.txt 命令:x

    4、删除/opt/server/tomcat/logs/ 下所有不包括“catalina.out”的5天前的文件

    find /opt/server/tomcat/logs/ -mtime +5 -type f -not ( -name 'catalina.out*' ) -delete

    5、查找替换

    [root@auto hzb]# cat init-ip.sh 
    #!/bin/bash
    ONEX_NODE_IP=172.16.101.251
    PKG_NODE_IP=172.16.101.250
    CC_NODE_IP=172.16.12.7
    
    
    
    
    
    
    
    
    
    find  .  -type f |grep -v init-ip.sh|xargs sed  -i 's#{ONEX_IP}#'"$ONEX_NODE_IP"'#g'
    find  .  -type f |grep -v init-ip.sh|xargs sed  -i 's#{PKG_IP}#'"$PKG_NODE_IP"'#g'
    find  .  -type f |grep -v init-ip.sh|xargs sed  -i 's#{CC_IP}#'"$CC_NODE_IP"'#g'
  • 相关阅读:
    Python基础之初始编码
    Excel图表编辑---表格移动,样式修改
    Python基础之Python的变量、常量
    刷题62. Unique Paths
    刷题56. Merge Intervals
    刷题55. Jump Game
    刷题53. Maximum Subarray
    刷题49. Group Anagrams
    刷题48. Rotate Image
    刷题46. Permutations
  • 原文地址:https://www.cnblogs.com/boshen-hzb/p/6594654.html
Copyright © 2011-2022 走看看