Flattern sub dirs&使用bash在文件名前添加dir名称

时间:2016-11-07 19:53:28

标签: linux bash shell ubuntu command-line-interface

这有效:

Matthews-MBP:WTB matthewwyeth$ rm -Rf Pods; pod install
Analyzing dependencies
Pre-downloading: `Alamofire` from    `https://github.com/Alamofire/Alamofire.git`, tag `4.0.0`
Pre-downloading: `SwiftyJSON` from    `https://github.com/BaiduHiDeviOS/SwiftyJSON.git`, commit     `de5dc3b1b421805769590d331178551bbb0e5733`
[!] Unable to satisfy the following requirements:

- `Alamofire (from `https://github.com/Alamofire/Alamofire.git`, tag   `4.0.0`)` required by `Podfile`
- `Alamofire (= 4.0.0)` required by `Podfile.lock`
- `Alamofire (~> 3.0)` required by `GooglePlaces (1.0.1)`

[!] Your Podfile has had smart quotes sanitised. To avoid issues in the            future, you should not use TextEdit for editing it. If you are not using            TextEdit, you should turn off smart quotes in your editor of choice.

但我希望在文件名前加上目录名" e.g。

ls -SF data/*/*/* | xargs -I % cp % migrations/db.tmp/

我尝试的下一步是:(但无法让它发挥作用)

data/folder1/subfolder1/file1.js -> data/folder1-subfolder1-file1.js

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

请勿使用ls,尤其是-F选项:

cd data
for f in */*/*; do cp "$f" "${f//\//-}"; done

这是一个更棘手的方法

cd data
printf "%s\n" */*/* | sed 'h; s,/,-,g; x; G; s/\n/ /; s/^/cp /'

这将输出一堆cp命令。管道进入| sh以执行它们。