The following methods are used to modify file name suffixes in batches in Linux: Use the rename command: rename 's/old suffix/new suffix/' *. Use the mv command for the old suffix: mv. old suffix. Use the shell for the new suffix. Script: for file in *.old suffix; do mv "$file" "${file%.old suffix}.new suffix"done use find command: find . -name "*.old suffix" -exec rename 's/ .old suffix/.new suffix/' {}
How to batch modify the file name suffix in Linux
In Linux, batch modification of file name suffixes is a common and convenient task. There are many ways to achieve this. Here are some commonly used methods:
Use the rename command
The rename command is a powerful tool dedicated to renaming files and directories.
<code>rename 's/旧后缀/新后缀/' *. 旧后缀</code>
For example, to change the suffix of all .txt files to .md, use the following command:
<code>rename 's/.txt/.md/' *.txt</code>
Use the mv command
mv Commands can be used to move or rename files.
<code>mv *.旧后缀 *.新后缀</code>
For example, to change the suffix of all .jpg files to .png, use the following command:
<code>mv *.jpg *.png</code>
Use shell script
If If you need more complex batch rename operations, you can use shell scripts.
<code>#!/bin/bash for file in *.旧后缀; do mv "$file" "${file%.旧后缀}.新后缀" done</code>
For example, to change the suffix of all .mp4 files to .mov, use the following script:
<code>#!/bin/bash for file in *.mp4; do mv "$file" "${file%.mp4}.mov" done</code>
Use the find command
find Commands can be used to search and modify files.
<code>find . -name "*.旧后缀" -exec rename 's/.旧后缀/.新后缀/' {} +</code>
For example, to change the suffix of all .html files to .php, use the following command:
<code>find . -name "*.html" -exec rename 's/.html/.php/' {} +</code>
The above is the detailed content of How to batch modify file name suffixes in Linux. For more information, please follow other related articles on the PHP Chinese website!