linux - 从特定目录开始复制文件路径 - Bash
问题描述
如何使用 Bash 从特定目录开始复制文件(包括它们的文件夹层次结构)?
例如,假设我有以下文件:
- /first/second/third/1.txt
- /first/third/2.txt
- /first/second/3.txt
我想复制/first/ 目录后的文件(1.txt、2.txt、3.txt)路径,意思是结果应该是:
- /second/third/1.txt
- /第三/2.txt
- /second/3.txt
使用以下命令,但不幸的是它包含了包括“第一个”目录在内的整个路径,因此需要进行一些调整:
find . -type f -name "*.txt" -exec cp --parent {} destination_folder/
有什么建议么?
解决方案
cd first
如果以前无法做到find
,请尝试在以下情况下进行-exec
:
find . -type f -name "*.txt" -exec bash -c 'cd first; echo cp --parent "${1#./*/}" ../destination_folder/' _ {} \;
推荐阅读
- python - 提高2个列表python的迭代速度
- electron - Electron osx systemPreferences.askForMediaAccess 应用程序崩溃
- r - r 未正确编码特殊字符
- java - 在应用程序日志文件中记录 Spring Boot Actuator 健康状态
- c# - 判断可能出现的字符串赋值运算符异常
- arrays - 如何在 Google 表格中对多个字符串使用 REGEXREPLACE
- html - 使用 CSS 更改下拉箭头颜色
- c# - 人脸检测网络摄像头显示空白屏幕打开 cv
- python - 如何将 4d numpy 图像数组转换为 3d?
- cordova - 在为 android 构建离子应用程序时无法读取未定义的属性“地图”