zoukankan      html  css  js  c++  java
  • xargs命令学习

    1.xargs复制文件

    目录下文件结构为:

    .
    
    ├── demo1
    
    │   ├── test.lua
    
    │   ├── test.php
    
    │   └── test.txt
    
    └── demo2
    

      

    执行命令:

    find ./demo1/ -name  'test*'|cp `xargs` ./demo2/
    

      

    目录结构为:

    .
    
    ├── demo1
    
    │   ├── test.lua
    
    │   ├── test.php
    
    │   └── test.txt
    
    └── demo2
    
        ├── test.lua
    
        ├── test.php
    
        └── test.txt
    
     
    

      

    2.xargs复制文件

    [root@lx xargsTest]# tree
    
    .
    
    ├── demo1
    
    │   ├── test.lua
    
    │   ├── test.php
    
    │   └── test.txt
    
    └── demo2
    
        ├── test.lua
    
        ├── test.php
    
        └── test.txt
    
    find ./demo1/ -name  'test*'|xargs -i cp {} {}.bak
    
    .
    
    ├── demo1
    
    │   ├── test.lua
    
    │   ├── test.lua.bak
    
    │   ├── test.php
    
    │   ├── test.php.bak
    
    │   ├── test.txt
    
    │   └── test.txt.bak
    
    └── demo2
    
        ├── test.lua
    
        ├── test.php
    
        └── test.txt
    

      

    3.xargs删除文件

    查询以.bak结尾的文件

     find ./demo1/ -name  '*.bak'
    

      

    ./demo1/test.txt.bak
    
    ./demo1/test.lua.bak
    
    ./demo1/test.php.bak
    

      

    删除这些文件

    find ./demo1/ -name  '*.bak'|xargs rm -fr
    

      

    [root@lx xargsTest]# tree
    
    .
    
    ├── demo1
    
    │   ├── test.lua
    
    │   ├── test.php
    
    │   └── test.txt
    
    └── demo2
    
        ├── test.lua
    
        ├── test.php
    
        └── test.txt
    

      

    删除成功

  • 相关阅读:
    ‘内部系统’怎么测试?两年测试的总结与反思
    微信公众号支付 -- 笔记
    数组处理
    String操作
    number 处理
    date 处理
    type检查
    全选全不选,返回字符串长度,汉字计数为2,获取url中的参数 ,函数防抖,函数节流
    关于移动端兼容BUG问题收集及处理
    nginx 1.6.0 配置文件服务器下载
  • 原文地址:https://www.cnblogs.com/lisqiong/p/5732850.html
Copyright © 2011-2022 走看看