iqu*_*oth 6 command-line find coreutils
有没有办法只用 find 命令在文件名前加上一个字符串?
所以这个:
201a.txt
201b.png
...
Run Code Online (Sandbox Code Playgroud)
变成这样:
foo_201a.txt
foo_201b.png
...
Run Code Online (Sandbox Code Playgroud)
这个:
find . -name '201*' -execdir mv {} foo_{} \;
Run Code Online (Sandbox Code Playgroud)
不起作用,因为该{}
部分包含./
文件名中的前导,因此尝试写入foo_./201*
.
如果仅使用 find 无法做到这一点,那么将字符串添加到文件名的最便携(阅读:只有 coreutils,没有 shell 脚本,最容易理解)的方法是什么?
不。但是该rename
命令提供了一个简单的解决方案。
$ ls -1
201a.txt
201b.png
$ rename 201 foo_201 201*
$ ls -1
foo_201a.txt
foo_201b.png
$
Run Code Online (Sandbox Code Playgroud)