Renaming multiple files with Bash [duplicate]
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
1
down vote
favorite
This question already has an answer here:
How to rename multiple files sequentially from command line?
6 answers
I have a lot of files to process and I need to replace their original names with this format in bash:
00000000000001_1.jpg
00000000000002_1.jpg
00000000000003_1.jpg
and so on
bash batch-rename
marked as duplicate by WinEunuuchs2Unix, waltinator, Byte Commander, Sergiy Kolodyazhnyy
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 19 at 23:15
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
1
down vote
favorite
This question already has an answer here:
How to rename multiple files sequentially from command line?
6 answers
I have a lot of files to process and I need to replace their original names with this format in bash:
00000000000001_1.jpg
00000000000002_1.jpg
00000000000003_1.jpg
and so on
bash batch-rename
marked as duplicate by WinEunuuchs2Unix, waltinator, Byte Commander, Sergiy Kolodyazhnyy
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 19 at 23:15
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
This question already has an answer here:
How to rename multiple files sequentially from command line?
6 answers
I have a lot of files to process and I need to replace their original names with this format in bash:
00000000000001_1.jpg
00000000000002_1.jpg
00000000000003_1.jpg
and so on
bash batch-rename
This question already has an answer here:
How to rename multiple files sequentially from command line?
6 answers
I have a lot of files to process and I need to replace their original names with this format in bash:
00000000000001_1.jpg
00000000000002_1.jpg
00000000000003_1.jpg
and so on
This question already has an answer here:
How to rename multiple files sequentially from command line?
6 answers
bash batch-rename
bash batch-rename
edited Mar 19 at 21:40
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
Zanna
48.1k13119228
48.1k13119228
asked Mar 19 at 21:32
![](https://i.stack.imgur.com/sffyj.jpg?s=32&g=1)
![](https://i.stack.imgur.com/sffyj.jpg?s=32&g=1)
deXterlab97
286
286
marked as duplicate by WinEunuuchs2Unix, waltinator, Byte Commander, Sergiy Kolodyazhnyy
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 19 at 23:15
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by WinEunuuchs2Unix, waltinator, Byte Commander, Sergiy Kolodyazhnyy
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 19 at 23:15
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
Adapted from one of Oli's answers:
rename -n 's/.+/our $i; $i++; sprintf("%014d_1.jpg", $i)/e' *
This takes every file in the current directory and renames it with a number with 14
digits (I hope I counted correctly) followed by _1.jpg
. our $i
introduces a global variable i
, which is then increased by one and printed with sprintf
. e
commands rename
to evaluate the right side of the replacement (= everything between the second and the third /
) as an expression rather than literally. If you're happy with the results, remove -n
to perform the renaming.
If you want to dive into perl expressions and their beauty, the perldoc is the way to go.
This is a good approach. The Perlrename
utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).
â Eliah Kagan
Mar 20 at 5:43
add a comment |Â
up vote
2
down vote
Would this works for you :
i=1
for file in *; do
mv "$file" "$(printf %014d $i)_1.jpg"
i=$((i+1))
done
It will rename every file in the current directory like this :
00000000000001_1.jpg
.
.
00000000000009_1.jpg
.
.
00000000000010_1.jpg
.
.
replace._$file
with_1.jpg
and I think you've got it.
â WinEunuuchs2Unix
Mar 19 at 23:10
I edited my answer, I thought _1.jpg was supposed to be the original file name.
â Paul
Mar 19 at 23:57
Looking better. Just need to change._1.jpg
to_1.jpg
then I think it's perfect.
â WinEunuuchs2Unix
Mar 20 at 1:48
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Adapted from one of Oli's answers:
rename -n 's/.+/our $i; $i++; sprintf("%014d_1.jpg", $i)/e' *
This takes every file in the current directory and renames it with a number with 14
digits (I hope I counted correctly) followed by _1.jpg
. our $i
introduces a global variable i
, which is then increased by one and printed with sprintf
. e
commands rename
to evaluate the right side of the replacement (= everything between the second and the third /
) as an expression rather than literally. If you're happy with the results, remove -n
to perform the renaming.
If you want to dive into perl expressions and their beauty, the perldoc is the way to go.
This is a good approach. The Perlrename
utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).
â Eliah Kagan
Mar 20 at 5:43
add a comment |Â
up vote
4
down vote
accepted
Adapted from one of Oli's answers:
rename -n 's/.+/our $i; $i++; sprintf("%014d_1.jpg", $i)/e' *
This takes every file in the current directory and renames it with a number with 14
digits (I hope I counted correctly) followed by _1.jpg
. our $i
introduces a global variable i
, which is then increased by one and printed with sprintf
. e
commands rename
to evaluate the right side of the replacement (= everything between the second and the third /
) as an expression rather than literally. If you're happy with the results, remove -n
to perform the renaming.
If you want to dive into perl expressions and their beauty, the perldoc is the way to go.
This is a good approach. The Perlrename
utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).
â Eliah Kagan
Mar 20 at 5:43
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Adapted from one of Oli's answers:
rename -n 's/.+/our $i; $i++; sprintf("%014d_1.jpg", $i)/e' *
This takes every file in the current directory and renames it with a number with 14
digits (I hope I counted correctly) followed by _1.jpg
. our $i
introduces a global variable i
, which is then increased by one and printed with sprintf
. e
commands rename
to evaluate the right side of the replacement (= everything between the second and the third /
) as an expression rather than literally. If you're happy with the results, remove -n
to perform the renaming.
If you want to dive into perl expressions and their beauty, the perldoc is the way to go.
Adapted from one of Oli's answers:
rename -n 's/.+/our $i; $i++; sprintf("%014d_1.jpg", $i)/e' *
This takes every file in the current directory and renames it with a number with 14
digits (I hope I counted correctly) followed by _1.jpg
. our $i
introduces a global variable i
, which is then increased by one and printed with sprintf
. e
commands rename
to evaluate the right side of the replacement (= everything between the second and the third /
) as an expression rather than literally. If you're happy with the results, remove -n
to perform the renaming.
If you want to dive into perl expressions and their beauty, the perldoc is the way to go.
edited Mar 19 at 23:20
answered Mar 19 at 23:13
![](https://i.stack.imgur.com/9L8vd.png?s=32&g=1)
![](https://i.stack.imgur.com/9L8vd.png?s=32&g=1)
dessert
19.8k55694
19.8k55694
This is a good approach. The Perlrename
utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).
â Eliah Kagan
Mar 20 at 5:43
add a comment |Â
This is a good approach. The Perlrename
utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).
â Eliah Kagan
Mar 20 at 5:43
This is a good approach. The Perl
rename
utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).â Eliah Kagan
Mar 20 at 5:43
This is a good approach. The Perl
rename
utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).â Eliah Kagan
Mar 20 at 5:43
add a comment |Â
up vote
2
down vote
Would this works for you :
i=1
for file in *; do
mv "$file" "$(printf %014d $i)_1.jpg"
i=$((i+1))
done
It will rename every file in the current directory like this :
00000000000001_1.jpg
.
.
00000000000009_1.jpg
.
.
00000000000010_1.jpg
.
.
replace._$file
with_1.jpg
and I think you've got it.
â WinEunuuchs2Unix
Mar 19 at 23:10
I edited my answer, I thought _1.jpg was supposed to be the original file name.
â Paul
Mar 19 at 23:57
Looking better. Just need to change._1.jpg
to_1.jpg
then I think it's perfect.
â WinEunuuchs2Unix
Mar 20 at 1:48
add a comment |Â
up vote
2
down vote
Would this works for you :
i=1
for file in *; do
mv "$file" "$(printf %014d $i)_1.jpg"
i=$((i+1))
done
It will rename every file in the current directory like this :
00000000000001_1.jpg
.
.
00000000000009_1.jpg
.
.
00000000000010_1.jpg
.
.
replace._$file
with_1.jpg
and I think you've got it.
â WinEunuuchs2Unix
Mar 19 at 23:10
I edited my answer, I thought _1.jpg was supposed to be the original file name.
â Paul
Mar 19 at 23:57
Looking better. Just need to change._1.jpg
to_1.jpg
then I think it's perfect.
â WinEunuuchs2Unix
Mar 20 at 1:48
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Would this works for you :
i=1
for file in *; do
mv "$file" "$(printf %014d $i)_1.jpg"
i=$((i+1))
done
It will rename every file in the current directory like this :
00000000000001_1.jpg
.
.
00000000000009_1.jpg
.
.
00000000000010_1.jpg
.
.
Would this works for you :
i=1
for file in *; do
mv "$file" "$(printf %014d $i)_1.jpg"
i=$((i+1))
done
It will rename every file in the current directory like this :
00000000000001_1.jpg
.
.
00000000000009_1.jpg
.
.
00000000000010_1.jpg
.
.
edited Mar 20 at 14:09
answered Mar 19 at 22:21
![](https://i.stack.imgur.com/otUDL.jpg?s=32&g=1)
![](https://i.stack.imgur.com/otUDL.jpg?s=32&g=1)
Paul
865
865
replace._$file
with_1.jpg
and I think you've got it.
â WinEunuuchs2Unix
Mar 19 at 23:10
I edited my answer, I thought _1.jpg was supposed to be the original file name.
â Paul
Mar 19 at 23:57
Looking better. Just need to change._1.jpg
to_1.jpg
then I think it's perfect.
â WinEunuuchs2Unix
Mar 20 at 1:48
add a comment |Â
replace._$file
with_1.jpg
and I think you've got it.
â WinEunuuchs2Unix
Mar 19 at 23:10
I edited my answer, I thought _1.jpg was supposed to be the original file name.
â Paul
Mar 19 at 23:57
Looking better. Just need to change._1.jpg
to_1.jpg
then I think it's perfect.
â WinEunuuchs2Unix
Mar 20 at 1:48
replace
._$file
with _1.jpg
and I think you've got it.â WinEunuuchs2Unix
Mar 19 at 23:10
replace
._$file
with _1.jpg
and I think you've got it.â WinEunuuchs2Unix
Mar 19 at 23:10
I edited my answer, I thought _1.jpg was supposed to be the original file name.
â Paul
Mar 19 at 23:57
I edited my answer, I thought _1.jpg was supposed to be the original file name.
â Paul
Mar 19 at 23:57
Looking better. Just need to change
._1.jpg
to _1.jpg
then I think it's perfect.â WinEunuuchs2Unix
Mar 20 at 1:48
Looking better. Just need to change
._1.jpg
to _1.jpg
then I think it's perfect.â WinEunuuchs2Unix
Mar 20 at 1:48
add a comment |Â