创建测试文件

[root@localhost mnt]# ls

[root@localhost mnt]# for i in {1..7};do touch wsyht$i.txt;done

[root@localhost mnt]# ll

total 0

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht1.txt

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht2.txt

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht3.txt

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht4.txt

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht5.txt

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht6.txt

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht7.txt


范例1:重命名文件名中的部分字符

[root@localhost mnt]# rename wsyht wsyht00 wsyht*

[root@localhost mnt]# ll

total 0

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht001.txt

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht002.txt

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht003.txt

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht004.txt

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht005.txt

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht006.txt

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht007.txt


范例2:重命名文件名结尾的扩展名txt为txl(扩展名可以认为是文件名的一部分)

[root@localhost mnt]# rename .txt .txl wsyht*

[root@localhost mnt]# ll

total 0

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht001.txl

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht002.txl

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht003.txl

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht004.txl

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht005.txl

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht006.txl

-rw-r--r--. 1 root root 0 Jun 18 15:29 wsyht007.txl