在ubuntu/bash下递归重命名文件和目录 [英] Rename files and directories recursively under ubuntu /bash
问题描述
我想将所有包含特殊"一词的文件和目录重命名为常规".它应该保持区分大小写,这样Special"就不会变成regular".
I want to rename all files and directories that contain the word "special" to "regular". It should maintain case sensitivity so "Special" won't become "regular".
我怎样才能在 bash 中递归地做到这一点?
How can i do this in bash recursively?
推荐答案
尝试这样做(需要 bash --version
>= 4):
Try doing this (require bash --version
>= 4):
shopt -s globstar
rename -n 's/special/regular/' **
当你的测试没问题时移除 -n
开关
Remove the -n
switch when your tests are OK
还有其他同名的工具可能会也可能不会能够做到这一点,所以要小心.
如果您运行以下命令 (GNU
)
If you run the following command (GNU
)
$ file "$(readlink -f "$(type -p rename)")"
你有一个像
.../rename: Perl script, ASCII text executable
并且不包含:
ELF
那么这似乎是正确的工具 =)
then this seems to be the right tool =)
如果没有,将其设为 Debian
和衍生产品(如 Ubuntu
)的默认设置(通常已经是这种情况):
If not, to make it the default (usually already the case) on Debian
and derivative like Ubuntu
:
$ sudo update-alternatives --set rename /path/to/rename
(将 /path/to/rename
替换为 perl 的 rename
命令的路径.
(replace /path/to/rename
to the path of your perl's rename
command.
如果你没有这个命令,搜索你的包管理器来安装它或者 手动操作
If you don't have this command, search your package manager to install it or do it manually
最后但并非最不重要的一点,这个工具最初是由 Perl 的父亲 Larry Wall 编写的.
Last but not least, this tool was originally written by Larry Wall, the Perl's dad.
这篇关于在ubuntu/bash下递归重命名文件和目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!