小编ott*_*tts的帖子

如何在 shell 命令行脚本中重命名文件名 - 用空格替换下划线

我正在尝试重命名文件夹中的所有文件,用空格替换下划线。

i.e. this_is_a_test --> this is a test
Run Code Online (Sandbox Code Playgroud)

但不知何故我搞砸了引用

> for file in * ; do echo mv -v $file $(echo $file | sed 's/_/\\ /g') ; done
mv -v this_is_a_test this\ is\ a\ test
Run Code Online (Sandbox Code Playgroud)

看起来不错,但是如果我删除“回声”,mv就像删除了反斜杠一样抱怨

> for file in * ; do mv -v $file $(echo $file | sed 's/_/\\ /g') ; done
mv: target ‘test’ is not a directory
Run Code Online (Sandbox Code Playgroud)

有人可以指出我方法的错误吗?

command-line bash

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

bash ×1

command-line ×1