shell批量修改文件后缀名
时间: 2024-05-06 10:17:39 浏览: 184
可以使用如下的命令批量修改文件后缀名:
```
$ for file in *.old_ext; do mv "$file" "${file%.old_ext}.new_ext"; done
```
上面的命令的作用是将当前目录下所有扩展名为 `.old_ext` 的文件修改为扩展名为 `.new_ext` 的文件。其中 `${file%.old_ext}` 表示去掉文件名中最后一个 `.old_ext` 扩展名,`${file%.old_ext}.new_ext` 则表示在去掉扩展名的基础上添加新的扩展名。
相关问题
shell批量修改后缀_linux下怎样批量更改文件后缀名
在Linux下批量修改文件后缀名可以使用脚本或者命令行方式,以下是两种方法:
1. 使用脚本
创建一个批量修改后缀名的脚本,例如:
```bash
#!/bin/bash
for file in *.txt
do
mv "$file" "${file%.txt}.md"
done
```
上面的脚本将当前目录下所有的 `.txt` 文件的后缀名修改为 `.md`。
注意:在执行脚本之前,需要在终端中进入到要修改后缀名的文件所在的目录。
2. 使用命令行
使用 `rename` 命令批量修改后缀名,例如:
```bash
rename 's/\.txt$/.md/' *.txt
```
上面的命令将当前目录下所有的 `.txt` 文件的后缀名修改为 `.md`。
注意:在执行命令之前,需要在终端中进入到要修改后缀名的文件所在的目录。另外,`rename` 命令在不同的 Linux 发行版中可能会有不同的实现方式,建议先查看该命令的帮助文档。
shell脚本批量修改文件后缀名
可以使用如下的 shell 脚本批量修改文件后缀名:
```bash
#!/bin/bash
for file in *.old_ext; do
mv -- "$file" "${file%.old_ext}.new_ext"
done
```
其中,`old_ext` 是原来的后缀名,`new_ext` 是要修改成的后缀名。
阅读全文
相关推荐















