改变——到。对于目录中的所有文件
我需要重命名目录中的所有文件。源文件名的一些示例如下:
alpha--sometext.381928
comp--moretext.7294058
结果文件将重命名为:
alpha.sometext.381928
comp.moretext.7294058
-- 之前和之后的字符数不一致。
该脚本需要在当前安装的 Ubuntu 和 FreeBSD 上运行。这些是精简的 LAMP 服务器,因此仅安装了必要的软件包。
谢谢
I need to rename all the files in a directory. Some examples of the source filenames are:
alpha--sometext.381928
comp--moretext.7294058
The resultant files would be renamed as:
alpha.sometext.381928
comp.moretext.7294058
The number of characters before and after the -- is not consistant.
The script needs to work on current installations of Ubuntu and FreeBSD. These are lean LAMP servers so only the necessary packages have been installed.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为纯 shell 的替代方案,您可以使用
rename
,这是 Perl 附带的标准实用程序。对于简单的情况来说更方便。As an alternative to pure shell, you can use
rename
, a standard utility that comes with Perl. It's more convenient for simple cases.通过 bash:
神奇之处在于
${file/--/.}
,它是${file}
的值,除了每个“--”更改为“ ”。Via bash:
The magic is in
${file/--/.}
which is the value of${file}
except with each "--" changed to a "."