Home >Operation and Maintenance >Linux Operation and Maintenance >How to batch modify file names in linux rename
Syntaxrename 's/src/dst/' *
*
can match any file and can add restrictions ( *.jpg)
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/' *
** plus $** will match the suffix
rename 's/.txt$/.jpg/' *
Add str
rename 's/$/str/' *
after the file name of all filesrename 's/$/txt/' *
Add txt
in batches Delete the str
## after the file name of all files #
rename 's/str$//' *Example
rename 's/txt$//' *Delete the
txt
# after the file name of all files ##5. Add prefix
rename 's/^/str/' *
Example
rename 's/^/hhh' * Add hhh before the file name
6. Delete the prefix
<pre class="brush:bash;">rename &#39;s/^str//&#39; *</pre>
Example
Delete the string starting with hhh
after the file name of all files
^strString ending in
str$Extension: usage of rename in linux shell
Format of C language version:
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:
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!