Home  >  Article  >  Operation and Maintenance  >  How to batch modify file names in linux rename

How to batch modify file names in linux rename

王林
王林forward
2023-05-14 23:04:045219browse

1. rename rename

Syntax
rename 's/src/dst/' * *can match any file and can add restrictions ( *.jpg)

2. Basic usage

When encountering the first matching string, replace it, and the following ones will not be replaced
only Matching the first .txt

rename 's/.txt/.jpg/' *

How to batch modify file names in linux rename

** plus $** will match the suffix

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

How to batch modify file names in linux rename

3. Add suffix

Add str

rename 's/$/str/' *

after the file name of all filesrename 's/$/txt/' * Add txt

How to batch modify file names in linux rename

after the file name 4. Delete the suffix

in batches Delete the str## after the file name of all files #

rename 's/str$//' *

Example

rename 's/txt$//' *Delete the txt

How to batch modify file names in linux rename# after the file name of all files ##5. Add prefix

Add str

rename 's/^/str/' *

Example

rename 's/^/hhh' *

Add hhh before the file name

How to batch modify file names in linux rename6. Delete the prefix

Delete the

str

<pre class="brush:bash;">rename &amp;#39;s/^str//&amp;#39; *</pre>Example

rename 's/^hhh//' *

Delete the string starting with hhh

How to batch modify file names in linux rename after the file name of all files

^str

String ending in str$
Extension: usage of rename in linux shell

rename is divided into two versions, namely C language version and Perl version

Format of C language version:

rename original string new string file name

Example:

When to modify The files are stored in the file folder in the subdirectory of the current directory. Prepare to replace all files containing linux with unix

(1) Currently in the file folder, the statement is rename linux unix *

(2) Currently in the parent directory of the file file, the statement is rename linux unix file/*

Perl version style:

rename 's/original character String/new string/' file name

Example:

The question is the same as the C language version question

(1) It is currently under the file folder, and the statement is rename 's/linux/unix/' *

(2) Currently in the parent directory of the file file, the statement is rename 's/linux/unix/' file/*

Note: now Basically the Perl version is used

The above is the detailed content of How to batch modify file names in linux rename. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete