zoukankan      html  css  js  c++  java
  • 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/

      

  • 相关阅读:
    MySQL优化
    MySQL 的 SQL 操作
    笔记本电脑同时使用两个网络
    top
    logrotate
    正则表达式学习总结
    HttpClient parameter 和body 传输同时进行
    Node.js背景
    前后端分离的理解
    shiro 的subject 以及Context 对象的具体的含义。
  • 原文地址:https://www.cnblogs.com/xusx/p/6041089.html
Copyright © 2011-2022 走看看