Ubuntu Bulk File Renaming

MayoMayn

BestDev
Oct 18, 2016
1,423
683
I'm wondering how do I bulk rename files? E.g I want to remove all characters before the first alphabetic character in each file without having to write a script that does it.
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
You should use the rename function, in which you can pass certain rules with regular expressions in order to modify the bulk to how you want.



Really easy to use.
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
You should use the rename function, in which you can pass certain rules with regular expressions in order to modify the bulk to how you want.



Really easy to use.
Thanks a lot.
But this doesn't seem to rename any file in my folder.
Code:
rename '/^[0-9\_]+/' *
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
This, otherwise all I can think is you have files that are like
a1b2c3
b2b3c4
c3b4c5

And you want to remove the char?? Clarify please.
Sorry for the late reply.

But here is an example of a bunch of images that have a number x_ infront of the real image filename.
I'm using a SWF decompiler that somehow thinks it's a good idea to add the key of the image to the file.
So I want to bulk rename all of these, to remove the annoying characters infront of the filename.
E.g "10_hair_M_jimmy_h_std_hr_2476_0_0.png" should become "hair_M_jimmy_h_std_hr_2476_0_0.png"
vplDwGp.png


And when I try to run rename '/^[0-9\_]+/' * in the folder nothing happens.
But if you take a look at the image below the regex is correct.

0BEtheh.png
 
Last edited:

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,396
960
sed -r 's/^[0-9]_+//g'

try:
Bash:
for file in *; do mv -v $file $(echo $file | sed -r 's/^[0-9]*[0-9]_+//g'); done

only tested with this kind of fake structure:
Code:
[root@ecko test]# for file in *; do mv -v $file $(echo $file | sed -r 's/^[0-9]*[0-9]_+//g'); done
'10_test_file_10.png' -> 'test_file_10.png'
'11_test_file_11.png' -> 'test_file_11.png'
'12_test_file_12.png' -> 'test_file_12.png'
'13_test_file_13.png' -> 'test_file_13.png'
'14_test_file_14.png' -> 'test_file_14.png'
'15_test_file_15.png' -> 'test_file_15.png'
'16_test_file_16.png' -> 'test_file_16.png'
'17_test_file_17.png' -> 'test_file_17.png'
'18_test_file_18.png' -> 'test_file_18.png'
'19_test_file_19.png' -> 'test_file_19.png'
'1_test_file_1.png' -> 'test_file_1.png'
'20_test_file_20.png' -> 'test_file_20.png'
'2_test_file_2.png' -> 'test_file_2.png'
'3_test_file_3.png' -> 'test_file_3.png'
'4_test_file_4.png' -> 'test_file_4.png'
'5_test_file_5.png' -> 'test_file_5.png'
'6_test_file_6.png' -> 'test_file_6.png'
'7_test_file_7.png' -> 'test_file_7.png'
'8_test_file_8.png' -> 'test_file_8.png'
'9_test_file_9.png' -> 'test_file_9.png'
 
Last edited:

Users who are viewing this thread

Top