bash - 将目录中的所有文件从 $filename_h 重命名为 $filename_half?

标签 bash shell

非常简单。

如何重命名

05_h.png
06_h.png

05_half.png
06_half.png

至少,我认为这很简单,但除非您已经知道,否则很难用 Google 搜索这种东西。

谢谢....

最佳答案

只使用bash,不需要调用外部命令。

for file in *_h.png
do
  mv "$file" "${file/_h.png/_half.png}"
done

不要添加#!/bin/sh

对于那些需要单线的人:

for file in *.png; do mv "$file" "${file/_h.png/_half.png}"; done

关于bash - 将目录中的所有文件从 $filename_h 重命名为 $filename_half?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7450818/

相关文章:

bash - 字符串的符号错误号

Android ADB 命令获取设备属性

shell - 如何禁用shell脚本vi编辑中的自动注释?

linux - Bash I/O 重定向

使用变量间接扩展的 Bash 数组扩展

linux - 测量进程的峰值磁盘使用

linux - 如何在 Linux shell 中复制带空格的多个目录

vba - 带引号的 Excel VBA Call Shell

bash - 许多Shell命令架构

linux - 在 bash 脚本中切换焦点