How to batch modify file names in linux rename

王林
Release: 2023-05-14 23:04:04
forward
5209 people have browsed it

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/' *
Copy after login

How to batch modify file names in linux rename

** plus $** will match the suffix

rename 's/.txt$/.jpg/' *
Copy after login

How to batch modify file names in linux rename

3. Add suffix

Add str

rename 's/$/str/' *
Copy after login

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$//' *
Copy after login

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/' *
Copy after login

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

<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:bash;">rename &amp;#39;s/^str//&amp;#39; *</pre><div class="contentsignin">Copy after login</div></div>Examplerename 's/^hhh//' *<p>Delete the string starting with <code>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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!