我使用find . -type f | grep " | "
并抓住:
./java notes | multithreading.txt
./deep/java notes | deep.txt
./deep/java notes | common.txt
./java notes | xml.txt
./java notes | keywords
./sql/java notes | sql
./EE/java notes | spring.txt
./EE/java notes | ws.txt
./EE/java notes | jstl.txt
./EE/java notes | jsp.txt
./java notes | net.txt
./java notes | exceptions.txt
./java notes | common.txt
./linux/linux | different. txt
在此之后我做find . -type f | grep " | " | sed "s/ | /_/"
并抓住:
./java notes_multithreading.txt
./deep/java notes_deep.txt
./deep/java notes_common.txt
./java notes_xml.txt
./java notes_keywords
./sql/java notes_sql
./EE/java notes_spring.txt
./EE/java notes_ws.txt
./EE/java notes_jstl.txt
./EE/java notes_jsp.txt
./java notes_net.txt
./java notes_exceptions.txt
./java notes_common.txt
./linux/linux_different. txt
我想附加xargs
来重命名所有这些文件,例如make sed
命令。或许还有其他方法可以解决它?我怎么能这样做?
答案 0 :(得分:0)
你可以在bash中使用for循环,如下所示:
for file in "$(find . -type f | grep " | ")"
do
mv "$file" "$(echo "$file" | sed "s/ | /_/")"
done
答案 1 :(得分:0)
可以使用perl重命名功能在一行中完成:
$ rename -v 's/\ \|\ /_/' *
> test | 123.txt renamed as test_123.txt