linux - 复制所有子目录的递归文件
问题描述
我想从一个不包含日志文件的目录中复制所有日志文件,但它包含其他带有日志文件的子目录。这些子目录还包含其他子目录,所以我需要一些递归的东西。
我试过了
cp -R *.log /destination
但它不起作用,因为第一个目录不包含日志文件。响应也可以是 bash 中的循环。
解决方案
find /path/to/logdir -type f -name "*.log" |xargs -I {} cp {} /path/to/destinationdir
解释:
find searches recursively
-type f tells you to search for files
-name specifies the name pattern
xargs executes commands
-I {} indicates an argument substitution symbol
另一个没有 xargs 的版本:
find /path/to/logdir -type f -name '* .log' -exec cp '{}' /path/to/destinationdir \;
推荐阅读
- delphi - Delphi 10.3.2 - 将项目添加到版本控制 - 导入到 SVN 崩溃 Delphi IDE
- r - R Windows:安装包“rvest”(和其他几个包)时出错
- javascript - 如何处理nodejs应用程序中的“ReferenceError:require is not defined”?
- dask - 如何有效地加入多个 dask 数据帧
- sql - Oracle APEX - 将隐藏的 SQL 查询下载到 CSV
- android - 具有网格布局延伸的回收站视图中的图像
- swift - 将 macos UI 冻结 30 秒——冥想
- apache-spark - Spark 结构化流式打印每批次每执行器的偏移量
- macos - 无法在 macos 上安装 web3
- r - R 版本 3.6.1(2019-07-05)(通过自制软件安装)在使用 terrain() 函数时因 seg 错误而崩溃