> For the complete documentation index, see [llms.txt](https://book.linh.eu.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.linh.eu.org/xi-tong-ruan-jian-cao-zuo/linux-pi-liang-xiu-gai-wen-jian-ming-qian-zhui-huo-hou-zhui.md).

# Linux 批量修改文件名（前缀或后缀）

有些文件的要求前缀或后缀要一样，或者批量的将文件重命名。

添加前缀：for i in \`ls\`; do mv -f $i \`echo "text\_"$i\`; done

替换后缀：rename 's/\\.txt/\\.csv/' \*

实例如下：

```
depuser@TSDEP61:/csdn$ ls
1.txt  2.txt  3.txt  4.txt  5.txt
depuser@TSDEP61:/csdn$ for i in `ls`; do mv -f $i `echo "text_"$i`; done
depuser@TSDEP61:/csdn$ ls
text_1.txt  text_2.txt  text_3.txt  text_4.txt  text_5.txt
depuser@TSDEP61:/csdn$ rename 's/\.txt/\.csv/' *
depuser@TSDEP61:/csdn$ ls
text_1.csv  text_2.csv  text_3.csv  text_4.csv  text_5.csv
```

[原文链接](https://blog.csdn.net/weixin_42003671/article/details/89920342)
