跳转至

批量重命名

方法一:使用rename命令(Perl 版本)

如果你的系统安装了 Perl 版的rename(大多数 Linux 发行版默认安装),可以直接执行:

Bash
rename 's/dump/input/' tempSrc_dump_index-*.ll
  • rename命令使用 Perl 正则表达式替换文件名

  • s/dump/input/将所有文件名中的dump替换为input

  • tempSrc_dump_index-*.ll指定匹配所有源文件

方法二:使用 Bash 脚本(兼容所有 Linux 系统)

如果没有 Perl 版rename,可以使用以下 Bash 脚本:

Bash
#!/bin/bash
for file in tempSrc_dump_index-*.ll; do
    new_name="${file/dump/input}"
    mv -- "$file" "$new_name"
done

使用步骤

  1. 将上述代码保存为rename_ll.sh
  2. 赋予执行权限:chmod +x rename_ll.sh
  3. 执行脚本:./rename_ll.sh

验证结果

执行后,所有文件将被重命名为:

C++
tempSrc_input_index-1.ll  tempSrc_input_index-10.ll  tempSrc_input_index-12.ll  tempSrc_input_index-14.ll  tempSrc_input_index-16.ll  tempSrc_input_index-2.ll  tempSrc_input_index-4.ll  tempSrc_input_index-6.ll  tempSrc_input_index-8.ll
tempSrc_input_index-11.ll  tempSrc_input_index-13.ll  tempSrc_input_index-15.ll  tempSrc_input_index-3.ll  tempSrc_input_index-5.ll  tempSrc_input_index-7.ll  tempSrc_input_index-9.ll