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 Linux rename command

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

Share

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

This article mainly introduces "how to use Linux rename command". In daily operation, I believe many people have doubts about how to use Linux rename command. Xiaobian consulted all kinds of information and sorted out simple and easy operation methods. I hope to help you answer the doubts about "how to use Linux rename command"! Next, please follow the small series to learn together!

rename Change file names in batches by replacing them with strings

There are two versions of rename command, which are different in usage.

C language version, support wildcard [common wildcard description] ? Represents an arbitrary character * Represents a character or string of arbitrary characters Perl version, supports regular expressions [Common regular expression notation] ^ Match input start position $ Matches the end of the input. Matches any character except newline + Matches the previous character one or more times For example,"zo+" matches "zoo" but not "z" [a-z] Represents a range of characters, for example,"[a-z]" matches any lowercase letter character between "a" and "z." [^m-z] Negative character interval. Matches characters that are not in the specified interval. Method of differentiation: rename --version

If util-linux is included in the returned result, it means the C language version, otherwise it means Perl version

# Perl version| Ubuntu(18),Mint(20) default Perl version $ rename --version /usr/bin/rename using File::Rename version 1.10 # C language version| Centos(7) defaults to C version $ rename --version rename from util-linux 2.23.2 syntax # Perl version rename [ -h|-m|-V ] [ -v ] [ -0 ] [ -n ] [ -f ] [ -d ] [ -e|-E perlexpr]*| perlexpr [ files ] # C language version rename [options] expression replaces character file... Parameters # Perl version-v, --verbose Detail: Print name of successfully renamed file. -0, --null When reading from STDIN, use\0 as the record separator-n, --nono Do nothing: Print the name of the file you want to rename, but do not rename it. -f, --force Overwrite: Allows overwriting of existing files--path, --fullpath Rename full path: Include any directory components. default-d, --filename, --nopath, --nofullpath Do not rename directories: rename only the filename portion of the path-h, --help Help: Print feeds and options. -m, --man Manual: Print manual pages. -V, --version Version: Displays the version number. -e Expression: Code applied to a file name. Code can be built repeatedly (such as "perl-e"). If there is no-e, the first argument is used as the code. -E Statement: Code that performs an operation on a file name, such as-e, but terminates in ';'. # C version-v, --verbose Provides visual feedback on which files, if any, are renamed-V, --version Display version information and exit. -s, --symlink rename on symbolic link target-h, --help Show Help Text and Exit Instance Perl Version Rename 1.txt 2.txt to 1.log 2.log

$ rename -v "s/txt/log/g" 1.txt 2.txt 1.txt renamed as 1.log 2.txt renamed as 2.log modify file suffix

rename "s//.html//.php/" * #Change.html suffix to.php suffix Add file suffix in batches

rename "s/$//.txt/" * #Delete file names in bulk with all file names ending in txt

rename "s//.txt//" * #Remove.txt from all filenames ending in.txt. C version renames 1.txt 2.txt to 1.log 2.log

$ rename -v txt log 1.txt 2.txt `1.txt' -> `1.log' `2.txt' -> `2.log' folder contains these files foo1, …, foo9, foo10, …, foo278

#Renaming files foo1 to foo9 to foo01 to foo09, renaming files only with 4 character names, replacing foo with foo0 in the file name. rename foo foo0 foo? All files # foo01 to foo99 are renamed foo001 to foo099, and only files with 5 character names are renamed, with foo replaced with foo0 in the file name. rename foo foo0 foo?? All files from # foo001 to foo278 were renamed foo0001 to foo0278, and all files starting with foo were renamed. rename foo foo0 foo* #All files from foo0200 to foo0278 are renamed foo200 to foo278, and foo0 in the file name is replaced with foo. rename foo0 foo0[2]* At this point, the study of "how to use Linux rename command" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

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