Friday, April 26, 2024
 Popular · Latest · Hot · Upcoming
98
rated 0 times [  98] [ 0]  / answers: 1 / hits: 89540  / 2 Years ago, wed, july 6, 2022, 9:54:23

I need to rename the following:



file_001_loremipsum.png
file_002_dolor.png
file_003_sit.png
file_004_amet.png
file_105_randomness.png


into



upl_loremipsum.png
upl_dolor.png
upl_sit.png
upl_amet.png
upl_randomness.png


How do I make it happen with just one simple line of terminal command?


More From » rename

 Answers
0

The solution to the above example, using rename:



rename -v -n 's/file_d{1,3}/upl/' file_*.png


Usage:



rename [options] [Perl regex search/replace expression] [files]


From man rename:



   -v, --verbose
Verbose: print names of files successfully renamed.
-n, --no-act
No Action: show what files would have been renamed.


rename MAY take regex as the arguments.



What we are looking at is the content between the single quotes '. You can place regex separated by /.



Formula: s/(1)/(2)/ where (1) = search pattern, and (2) = replace pattern.



So, familiarize youself with regex, and enjoy pattern based batch file renaming!


[#31686] Thursday, July 7, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tisglitter

Total Points: 307
Total Questions: 103
Total Answers: 119

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
tisglitter questions
Sun, Jan 9, 22, 16:18, 2 Years ago
Wed, Jun 1, 22, 18:03, 2 Years ago
Fri, Dec 10, 21, 14:31, 2 Years ago
;