【发布时间】:2017-03-06 23:04:18
【问题描述】:
我有一个 Windows 备份程序,它正在创建大量子目录,最后带有“$”。同一备份程序的 Linux 客户端在目录名称的末尾需要一个“:”,以便恢复文件夹。一些文件夹有“$”而其他文件夹没有 - 与内部版本控制系统有关。
如果我将文件从 windows 客户端恢复到另一个 windows 盒子,备份程序工作得很好。程序在 Windows 中使用“$”,因为“:”在路径中无效。
我正在寻找 bash 中的递归重命名,它将逐步遍历路径并找到最后带有单个“$”字符的所有文件夹,并将其替换为“:”
我的测试数据是这样的:
./a$
./b$
./c$
./white space$
./white space$/another test$
./white space$/another test$/a$
./white space$/another test$/b$
./white space$/another test$/x
./white space$/another test$/y
./white space$/test
./white space$/test 2
./white space$/testing$
我试过了:
find . -type d -name "*$"
这给了我需要重命名的文件夹列表
./a$
./b$
./c$
./white space$
./white space$/another test$
./white space$/another test$/a$
./white space$/another test$/b$
./white space$/testing$
find . -type d -name "*$" | sed 's/$$/\:/'
给出了我正在寻找的最终结果
./a:
./b:
./c:
./white space:
./white space$/another test:
./white space$/another test$/a:
./white space$/another test$/b:
./white space$/testing:
但我无法在同一步骤中重命名它。另外,我需要它以相反的顺序工作(从最深的匹配开始并返回),这样第一次重命名不会使其余的失败。
【问题讨论】: