In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
In Linux, we usually use the mv command to rename files, which is very convenient when renaming individual files. However, if we want to rename a set of files, mv is a bit weak. But it doesn't matter, today we're going to introduce a useful command that can be renamed in batches-the rename command.
Let's take a closer look at the use of the rename command.
Unlike the mv command, the rename command does not simply specify new and old file names. Instead, it uses regular expressions similar to Perl. Let's take a look at the example first.
$rename's Compact OldUniverse NewUniverse 'this.old$ ls this*this.new
Where the function of s is to specify that we replace the first string with the second string, thus changing this.old to this.new.
Some people may ask, isn't it more convenient for us to use the command mv this.old this.new in the above example? Yes, but such a command can only rename one file at a time, and what we need to do today is to rename a set of files at once.
What should I do with it? Quite simply, let's take a look at the following example:
$ls * .oldreport.old schedule.old stats.old this.old$ rename's Universe new old$ ls'*. Newreport.new schedule.new stats.old this.new
As can be seen from the above results, through the operation of this simple command, we can rename all files ending with .old in the current directory to files ending with .new, which is simple and efficient!
If you think that's all of the rename command, it's too young and too easy. The rename command is not limited to changing the file name extension, but can also change any string in the file name. For example, if we want to change the file named report.* to review.*, we can use the following command:
$rename's Compact reportUniverse
Note that the rules provided in regular expressions can change any part of the file name, whether it is the file name or the extension.
$rename's ls 123Universe 124max'* $Universe * 124*status.124 report124.txt
If you want to use rename interactively for renaming to make it easier to see what changes have been made to avoid erroneous modifications, use the-v option.
$rename-v's status.123 renamed as status.124report123.txt renamed as report124.txt 123max 124max'*
The-v option is to give you a preview when you want to change a piece of text, and then give you a preview when you change it, which is less efficient. What if I want to preview it as a whole and modify it all at once when I confirm that there is no problem?
We can use the-n or-- nono options to have the rename command implement the above requirements.
* rename (logger.man-old, logger.man-save) rename (lyrics.txt-old, lyrics.txt-save) rename (olderfile-, saveerfile-) rename (oldfile, savefile) rename (review.old, review.save) rename (schedule.old, schedule.save) rename (stats.old, stats.save) rename (this.old, this.save)
If you have no problem with the above changes, you can formally modify the file name by removing the-n option.
Notice that in the rename regular expression. Not a normal English full stop, but a wildcard that matches any character, which we can understand with reference to the following command.
* rename (logger.man-old, logger.man.save) rename (lyrics.txt-old, lyrics.txt.save) rename (review.old, review.save) rename (schedule.old, schedule.save) rename (stats.old, stats.save) rename (this.old, this.save)
In the above example, not only .old is changed to .save, but-old is also changed to .save.
If you want to. To indicate a full stop, you need to add a\ escape symbol, even if you use\. It means a full stop in English.
$rename-n's /\ .old /\ .save /'* rename (review.old, review.save) rename (schedule.old, schedule.save) rename (stats.old, stats.save) rename (this.old, this.save)
To change all uppercase letters to lowercase letters, we can use the following command.
W*rename (WARNING_SIGN.pdf, warning_sign.pdf) rename (Will_Gardner_buttons.pdf, will_gardner_buttons.pdf) rename (Wingding_Invites.pdf, wingding_invites.pdf) rename (WOW-buttons.pdf, wow-buttons.pdf)
Where-n is used to preview the changes to be made, and y means to change the case.
In the above example, we changed all file names that begin with the uppercase letter W to lowercase letters.
Summary
If you want to rename individual files, you can use the mv command. If you want to rename a group of files, then it is more convenient to use the rename command. Note that it is best to add the-n option to use the rename command, preview the changes to be made first, confirm them correctly, and then rename them to avoid accidents.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.