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 to use the common command rename in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you how to use the Linux command rename. I hope you will get something after reading this article. Let's discuss it together.

The Linux common command rename command changes the file name in batches by string substitution.

Syntax rename (parameter) parameter original string: the string that the file name needs to be replaced

Target string: replaces the original characters contained in the file name with the target string

File: specifies the list of files whose names you want to change.

Instance renaming

# rename main1.c to main.c rename main1.c main.c main1.c 12rename supports wildcards

? Can replace a single character * can replace multiple characters [charset] can replace any single character 123 folder in the charset set to have these files foo1, … , foo9, foo10, , foo278

If you use rename foo foo0 foo?, to rename a foo1-to-foo9 file to foo01 to foo09, the renamed file is just a file with a four-character name, and the foo in the file name is replaced with foo0.

If all files that use rename foo foo0 foo??,foo01 to foo99 are renamed to foo001 to foo099, only files with five character names are renamed, and the foo in the file name is replaced with foo0.

If all files that use rename foo foo0 foo*,foo001 to foo278 are renamed foo0001 to foo0278, all files that start with foo are renamed.

If you use rename foo0 foo foo0 [2] *, all files from foo0200 to foo0278 are renamed foo200 to foo278, and the foo0 in the file name is replaced with foo.

Rename supports regular expressions

# replace the AA in the file name with aa rename "s/AA/aa/" * # change the .html suffix to the .php suffix rename "s//.html//.php/" * # all file names end in txt rename "s/$//.txt/" * # delete rename "s//.txt//" from all file names ending in .txt * I have finished reading this article I believe you have a certain understanding of "how to use Linux commands rename". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

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