How can I batch change file extensions in Linux?

In Linux, you can use the rename command to bulk change file name extensions. The syntax for the rename command is as follows:

rename 's/旧后缀/新后缀/' 文件名模式

In this case, the old suffix refers to the original suffix you want to replace, the new suffix is the new suffix you want to replace it with, and the file name pattern is the pattern of the file names you want to match.

For example, if you want to change all .txt files to .doc files, you can use the following command:

rename 's/.txt$/.doc/' *.txt

This will change all file names ending with .txt in the current directory to end with .doc.

It is important to be careful when using the rename command, ensuring that the file name pattern you input only matches the files you want to change the suffix of. Otherwise, you may accidentally modify other files. Before executing the rename command, it is best to use the ls command to check if the file names match appropriately.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds