Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Linux rename files in batches

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article editor for you a detailed introduction of "Linux how to batch rename files", the content is detailed, the steps are clear, the details are handled properly, I hope this "Linux how to batch rename files" article can help you solve your doubts, the following follow the editor's ideas slowly in-depth, together to learn new knowledge.

The basic syntax for batch renaming files through the rename command rename [- n-v-f] 'pcre' is an Perl-compatible regular expression that represents the file to be renamed and what to do. The regular expression is in the form of'sAccordLay _ name_ _ new _

The'- v 'option shows the details of the file name change (for example, rename XXX to YYY).

The'- n 'option tells the rename command to show that the file will be renamed without actually changing the name. This option is useful if you want to simulate a file name change without changing the file name.

The'- f 'option forces existing files to be overwritten.

Example 1. Change the file extension suppose you have many .jpeg image files, and you want to change their names to .jpg. The following command changes the .jpeg file to * .jpg.

Rename's /\ .jpeg /\ .jpg /'* .jpeg2. Change uppercase to lowercase sometimes if you want to change the case of a file name, you can use the following command.

Change all the files to lowercase

Rename'yax Amura Zantha * change all files to uppercase.

Rename'yque a Muyza * * 3. Changing the filename pattern now lets us consider more complex regular expressions that contain subpatterns. In PCRE, the subpattern is contained in parentheses, followed by a number (for example, 1 ~ 2).

The following command turns' imgNNNN.jpeg' into 'danNNNN.jpg'. 1 root@root:~$ rename-v's jpeg img_5417.jpeg renamed as dan_5417.jpg img_5418.jpeg renamed as dan_5418.jpg img_5419.jpeg renamed as dan_5419.jpg img_5420.jpeg renamed as dan_5420.jpg img_5421.jpeg renamed as dan_5421.jpg img_5422.jpeg renamed as dan_5422.jpg IMG _ (\ d {4})\ .jpeg / dan_$1.jpg/' * .jpeg 1234567 the following command sets the 'img_000NNNN .jpeg 'becomes' dan_NNNN.jpg'. 1 root@root:~$ rename-v's Charpy IMG _\ d {3} (\ d {4})\ .jpeg / dan_$1.jpg/' * .jpeg img_0005417.jpeg renamed as dan_5417.jpg img_0005418.jpeg renamed as dan_5418.jpg img_0005419.jpeg renamed as dan_5419.jpg img_0005420.jpeg renamed as dan_5420.jpg img_0005421.jpeg renamed as dan_5421.jpg img_0005422.jpeg renamed as dan_5422.jpg 1234567 in the above example The subpattern'\ d {4} 'captures four consecutive digits, and the captured four numbers match the pattern corresponding to $1, which will be used for the new file name.

After reading this, the article "how to rename files in batches in Linux" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report