• find ./ -name *.bak | xargs rm/mv


    #####################################################################################################

    #find ... -exec rm {} ; 

    可以把find命令查找到的结果删除,简单的说是把find发现的结果一次性传给exec选项,这样当文件数量较多的时候,就可能会出现“参数太多”之类的错误。

    -exec   必须由一个   ;   结束,而因为通常   shell   都会对   ;   进行处理,所以用   ;   防止这种情况。{} 可能需要写做   '{}',也是为了避免被   shell   过滤 

    eg1:

    [root@localhost xusx]# touch 1.sh 2.sh 3.sh 1.txt 2.txt 3.txt
    [root@localhost xusx]# ls
    1.sh 1.txt 2.sh 2.txt 3.sh 3.txt passwd
    [root@localhost xusx]# find ./ -type f ! -name "passwd" -exec rm {} ; (删除passwd之外的文件)

    [root@localhost xusx]# ls
    1.sh 1.txt 2.sh 2.txt 3.sh 3.txt

    #####################################################################################################

    #find ... | xargs rm -rf

    这个命令可以避免这个错误,因为xargs命令会分批次的处理结果。这样看来,“find ... | xargs rm -rf”是更通用的方法,推荐使用!

    rm不接受标准输入,所以不能用find / -name "tmpfile" |rm

    eg1:

    [root@localhost xusx]# ls
    1.sh 1.txt 2.sh 2.txt 3.sh 3.txt

    [root@localhost xusx]# find ./ -type f -name "1.sh"|xargs rm -f
    [root@localhost xusx]# ls
    1.txt 2.sh 2.txt 3.sh 3.txt

    #####################################################################################################

    ./表示从当前目录找 
    -type f,表示只找file,文件类型的,目录和其他字节不要 
    -exec 把find到的文件名作为参数传递给后面的命令行,代替{}的部分 
    -exec后跟的命令行,必须用“ ;”结束

    #####################################################################################################

    经典的移动:man mv
    find ./  -type f -name "*.sh"|xargs mv -t /opt/
    find ./  -type f -name "*.sh"|xargs -i mv {} /opt/
    find ./  -type f -name "*.sh" -exec mv {} /opt/ ;  =====>转意符号。否则 ; 不被shell识别。
    mv `find ./  -type f -name "*.sh"` /opt/  或者  cp $(find ./  -type f -name "*.sh" ) /opt/

      

  • 相关阅读:
    Thrift官方安装手冊(译)
    从用python做zoj1011发生Non-zero Exit Code错误说起
    POJ 1637 Sightseeing tour(最大流)
    js中substr与substring的差别
    白话经典算法系列之七 堆与堆排序
    在基于阿里云serverCentOS6.5下安装Subversion 1.6.5服务
    Android研究之手PullToRefresh(ListView GridView 下拉刷新)使用具体解释
    java中获取系统属性以及环境变量
    sql中 in 、not in 、exists、not exists 使用方法和区别
    80x86汇编小站站长简单介绍-2014年08月23日
  • 原文地址:https://www.cnblogs.com/xusx/p/6041089.html
Copyright © 2020-2023  润新知