How to rename all .jpg files in all subdirs wich contains dash in linux? [closed]
![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
I have subfolders with dashes (example subdir with name c-d). I need to rename all .jpg files in all subdirs. Any tips how to do it? I've tried many options, but nothing helped (I think because my subfolders contains dashes -) Thanks guys! :)
I have tried
find -name '*.jpg' -exec rename $RANDOM.jpg $RANDOM.jpg ;
but getting
(Missing operator before jpg?) syntax error at (user-supplied code)
line 3, near "2635.jpg" Bareword found where operator expected at
(eval 4) line 1, near "#line 1 2635.jpg"
command-line rename batch-rename
closed as unclear what you're asking by David Foerster, Zanna, Eric Carvalho, user68186, muru Feb 8 at 6:07
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
 |Â
show 4 more comments
up vote
-1
down vote
favorite
I have subfolders with dashes (example subdir with name c-d). I need to rename all .jpg files in all subdirs. Any tips how to do it? I've tried many options, but nothing helped (I think because my subfolders contains dashes -) Thanks guys! :)
I have tried
find -name '*.jpg' -exec rename $RANDOM.jpg $RANDOM.jpg ;
but getting
(Missing operator before jpg?) syntax error at (user-supplied code)
line 3, near "2635.jpg" Bareword found where operator expected at
(eval 4) line 1, near "#line 1 2635.jpg"
command-line rename batch-rename
closed as unclear what you're asking by David Foerster, Zanna, Eric Carvalho, user68186, muru Feb 8 at 6:07
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
4
What exactly is the intent of$RANDOM.jpg $RANDOM.jpg
?rename
expects a valid Perl expression telling it what to rename the files from and to
â steeldriver
Feb 6 at 13:58
I don't know because i've found it in the web. So how i can rename to a random name all .jpg files in all subdirs? Thanks for your answer, steeldriver
â Jane Farrow
Feb 6 at 14:01
2
Are you sure you want to rename all your Jpegs to something likeXrUg2oCLIIoBGwH.jpg
,l9OD0lus8Ft1LJ9.jpg
, and73k9qXms3rIH2Mr.jpg
? I'm looking forward to reading a question about getting rid of files with weird names then.
â PerlDuck
Feb 6 at 14:17
1
Maybe the sybtax of the find should befind -name '*.jpg' -exec rename $RANDOM.jpg ;
That will rename each .jpg file found () to the content of $RANDOM with .jpg added.
â Soren A
Feb 6 at 14:34
4
@SorenA That will rename all files to the same name because$RANDOM
gets evaluated only once.
â PerlDuck
Feb 6 at 14:40
 |Â
show 4 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have subfolders with dashes (example subdir with name c-d). I need to rename all .jpg files in all subdirs. Any tips how to do it? I've tried many options, but nothing helped (I think because my subfolders contains dashes -) Thanks guys! :)
I have tried
find -name '*.jpg' -exec rename $RANDOM.jpg $RANDOM.jpg ;
but getting
(Missing operator before jpg?) syntax error at (user-supplied code)
line 3, near "2635.jpg" Bareword found where operator expected at
(eval 4) line 1, near "#line 1 2635.jpg"
command-line rename batch-rename
I have subfolders with dashes (example subdir with name c-d). I need to rename all .jpg files in all subdirs. Any tips how to do it? I've tried many options, but nothing helped (I think because my subfolders contains dashes -) Thanks guys! :)
I have tried
find -name '*.jpg' -exec rename $RANDOM.jpg $RANDOM.jpg ;
but getting
(Missing operator before jpg?) syntax error at (user-supplied code)
line 3, near "2635.jpg" Bareword found where operator expected at
(eval 4) line 1, near "#line 1 2635.jpg"
command-line rename batch-rename
command-line rename batch-rename
edited Feb 7 at 0:28
muru
130k19275470
130k19275470
asked Feb 6 at 13:52
![](https://i.stack.imgur.com/TAaMU.jpg?s=32&g=1)
![](https://i.stack.imgur.com/TAaMU.jpg?s=32&g=1)
Jane Farrow
1
1
closed as unclear what you're asking by David Foerster, Zanna, Eric Carvalho, user68186, muru Feb 8 at 6:07
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by David Foerster, Zanna, Eric Carvalho, user68186, muru Feb 8 at 6:07
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
4
What exactly is the intent of$RANDOM.jpg $RANDOM.jpg
?rename
expects a valid Perl expression telling it what to rename the files from and to
â steeldriver
Feb 6 at 13:58
I don't know because i've found it in the web. So how i can rename to a random name all .jpg files in all subdirs? Thanks for your answer, steeldriver
â Jane Farrow
Feb 6 at 14:01
2
Are you sure you want to rename all your Jpegs to something likeXrUg2oCLIIoBGwH.jpg
,l9OD0lus8Ft1LJ9.jpg
, and73k9qXms3rIH2Mr.jpg
? I'm looking forward to reading a question about getting rid of files with weird names then.
â PerlDuck
Feb 6 at 14:17
1
Maybe the sybtax of the find should befind -name '*.jpg' -exec rename $RANDOM.jpg ;
That will rename each .jpg file found () to the content of $RANDOM with .jpg added.
â Soren A
Feb 6 at 14:34
4
@SorenA That will rename all files to the same name because$RANDOM
gets evaluated only once.
â PerlDuck
Feb 6 at 14:40
 |Â
show 4 more comments
4
What exactly is the intent of$RANDOM.jpg $RANDOM.jpg
?rename
expects a valid Perl expression telling it what to rename the files from and to
â steeldriver
Feb 6 at 13:58
I don't know because i've found it in the web. So how i can rename to a random name all .jpg files in all subdirs? Thanks for your answer, steeldriver
â Jane Farrow
Feb 6 at 14:01
2
Are you sure you want to rename all your Jpegs to something likeXrUg2oCLIIoBGwH.jpg
,l9OD0lus8Ft1LJ9.jpg
, and73k9qXms3rIH2Mr.jpg
? I'm looking forward to reading a question about getting rid of files with weird names then.
â PerlDuck
Feb 6 at 14:17
1
Maybe the sybtax of the find should befind -name '*.jpg' -exec rename $RANDOM.jpg ;
That will rename each .jpg file found () to the content of $RANDOM with .jpg added.
â Soren A
Feb 6 at 14:34
4
@SorenA That will rename all files to the same name because$RANDOM
gets evaluated only once.
â PerlDuck
Feb 6 at 14:40
4
4
What exactly is the intent of
$RANDOM.jpg $RANDOM.jpg
? rename
expects a valid Perl expression telling it what to rename the files from and toâ steeldriver
Feb 6 at 13:58
What exactly is the intent of
$RANDOM.jpg $RANDOM.jpg
? rename
expects a valid Perl expression telling it what to rename the files from and toâ steeldriver
Feb 6 at 13:58
I don't know because i've found it in the web. So how i can rename to a random name all .jpg files in all subdirs? Thanks for your answer, steeldriver
â Jane Farrow
Feb 6 at 14:01
I don't know because i've found it in the web. So how i can rename to a random name all .jpg files in all subdirs? Thanks for your answer, steeldriver
â Jane Farrow
Feb 6 at 14:01
2
2
Are you sure you want to rename all your Jpegs to something like
XrUg2oCLIIoBGwH.jpg
, l9OD0lus8Ft1LJ9.jpg
, and 73k9qXms3rIH2Mr.jpg
? I'm looking forward to reading a question about getting rid of files with weird names then.â PerlDuck
Feb 6 at 14:17
Are you sure you want to rename all your Jpegs to something like
XrUg2oCLIIoBGwH.jpg
, l9OD0lus8Ft1LJ9.jpg
, and 73k9qXms3rIH2Mr.jpg
? I'm looking forward to reading a question about getting rid of files with weird names then.â PerlDuck
Feb 6 at 14:17
1
1
Maybe the sybtax of the find should be
find -name '*.jpg' -exec rename $RANDOM.jpg ;
That will rename each .jpg file found (
) to the content of $RANDOM with .jpg added.â Soren A
Feb 6 at 14:34
Maybe the sybtax of the find should be
find -name '*.jpg' -exec rename $RANDOM.jpg ;
That will rename each .jpg file found (
) to the content of $RANDOM with .jpg added.â Soren A
Feb 6 at 14:34
4
4
@SorenA That will rename all files to the same name because
$RANDOM
gets evaluated only once.â PerlDuck
Feb 6 at 14:40
@SorenA That will rename all files to the same name because
$RANDOM
gets evaluated only once.â PerlDuck
Feb 6 at 14:40
 |Â
show 4 more comments
3 Answers
3
active
oldest
votes
up vote
2
down vote
There is no case for rename, because you may just do it with mv.
find -name '*.jpg' -exec bash -c 'mv -i "" "$RANDOM.jpg"' ;
mv -i means interactive. It asks before overwriting.
This is not testet in depth, just ad hoc, to make sure files will get different names. A little more testing would be:
find -name '*.jpg' -exec echo bash -c 'mv -i "" "$RANDOM.jpg"' ;
However, this will put all files to the current dir. Maybe using -execdir is an option?
find -name '*.jpg' -execdir bash -c 'mv -i "" "$RANDOM.jpg"' ;
However, make a backup, be careful about your data and so on. Mass actions with find are a sharp instrument. I take no responsibility.
AFAIK dashes have no horses in this race.
Especially the third one is perfect, but the purpose of this whole thing is still obscure. To me, at least.
â PerlDuck
Feb 6 at 17:14
This is the right approach IMHO except that you might considerbash -c 'for f; do mv -i -- "$f" "$RANDOM.jpg"; done' bash +
(for efficiency, and to avoid expansion of theinside the command string). The OP could also consider using something like
"$(mktemp --suffix=.jpg --tmpdir=. XXXXXX)"
in place of$RANDOM
since the latter is not guaranteed to be unique.
â steeldriver
Feb 6 at 17:17
Did you test for efficiency? What did you get? IMHO, this action will be harddrive limited, so trying to read and write at the same time might end up in worse performance. It's an additional layer of complexity, and I've learned to just do it right, and later care for performance, and only, if necessary. But I'm very interested in numbers, so if you have made some measurements, be invited! Because I hear such advice often, in connection with find ";" and +.
â user unknown
Feb 6 at 17:21
add a comment |Â
up vote
0
down vote
You're unclear about how you want files to renamed. As far as which files to rename you can use find
to match all files according you the desired pattern containing a dash:
find [PATH...] -type f -name '*-*' | prename EXPR
If you want to match directories too you need to use the -depth
option:
find [PATH...] -depth -name '*-*' | prename EXPR
1
I think the OP is mistakenly attributing therename
error to the fact that their directories have dashes in their names
â steeldriver
Feb 6 at 16:16
add a comment |Â
up vote
0
down vote
I just tried this on sub-folders with a dash in their name, and it worked.
Renaming Portions of Filenames Recusively in Linux/Ubuntu
To rename files, you use the find command in conjunction with the rename command like this:
find -type f -execdir rename 's/OriginalText/NewText/' *.jpg '' ;
So if you want to replace all the dashes "-" in all the jpg filenames with underscores "_" then you would enter:
find -type f -execdir rename 's/-/_/' *.jpg '' ;
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
There is no case for rename, because you may just do it with mv.
find -name '*.jpg' -exec bash -c 'mv -i "" "$RANDOM.jpg"' ;
mv -i means interactive. It asks before overwriting.
This is not testet in depth, just ad hoc, to make sure files will get different names. A little more testing would be:
find -name '*.jpg' -exec echo bash -c 'mv -i "" "$RANDOM.jpg"' ;
However, this will put all files to the current dir. Maybe using -execdir is an option?
find -name '*.jpg' -execdir bash -c 'mv -i "" "$RANDOM.jpg"' ;
However, make a backup, be careful about your data and so on. Mass actions with find are a sharp instrument. I take no responsibility.
AFAIK dashes have no horses in this race.
Especially the third one is perfect, but the purpose of this whole thing is still obscure. To me, at least.
â PerlDuck
Feb 6 at 17:14
This is the right approach IMHO except that you might considerbash -c 'for f; do mv -i -- "$f" "$RANDOM.jpg"; done' bash +
(for efficiency, and to avoid expansion of theinside the command string). The OP could also consider using something like
"$(mktemp --suffix=.jpg --tmpdir=. XXXXXX)"
in place of$RANDOM
since the latter is not guaranteed to be unique.
â steeldriver
Feb 6 at 17:17
Did you test for efficiency? What did you get? IMHO, this action will be harddrive limited, so trying to read and write at the same time might end up in worse performance. It's an additional layer of complexity, and I've learned to just do it right, and later care for performance, and only, if necessary. But I'm very interested in numbers, so if you have made some measurements, be invited! Because I hear such advice often, in connection with find ";" and +.
â user unknown
Feb 6 at 17:21
add a comment |Â
up vote
2
down vote
There is no case for rename, because you may just do it with mv.
find -name '*.jpg' -exec bash -c 'mv -i "" "$RANDOM.jpg"' ;
mv -i means interactive. It asks before overwriting.
This is not testet in depth, just ad hoc, to make sure files will get different names. A little more testing would be:
find -name '*.jpg' -exec echo bash -c 'mv -i "" "$RANDOM.jpg"' ;
However, this will put all files to the current dir. Maybe using -execdir is an option?
find -name '*.jpg' -execdir bash -c 'mv -i "" "$RANDOM.jpg"' ;
However, make a backup, be careful about your data and so on. Mass actions with find are a sharp instrument. I take no responsibility.
AFAIK dashes have no horses in this race.
Especially the third one is perfect, but the purpose of this whole thing is still obscure. To me, at least.
â PerlDuck
Feb 6 at 17:14
This is the right approach IMHO except that you might considerbash -c 'for f; do mv -i -- "$f" "$RANDOM.jpg"; done' bash +
(for efficiency, and to avoid expansion of theinside the command string). The OP could also consider using something like
"$(mktemp --suffix=.jpg --tmpdir=. XXXXXX)"
in place of$RANDOM
since the latter is not guaranteed to be unique.
â steeldriver
Feb 6 at 17:17
Did you test for efficiency? What did you get? IMHO, this action will be harddrive limited, so trying to read and write at the same time might end up in worse performance. It's an additional layer of complexity, and I've learned to just do it right, and later care for performance, and only, if necessary. But I'm very interested in numbers, so if you have made some measurements, be invited! Because I hear such advice often, in connection with find ";" and +.
â user unknown
Feb 6 at 17:21
add a comment |Â
up vote
2
down vote
up vote
2
down vote
There is no case for rename, because you may just do it with mv.
find -name '*.jpg' -exec bash -c 'mv -i "" "$RANDOM.jpg"' ;
mv -i means interactive. It asks before overwriting.
This is not testet in depth, just ad hoc, to make sure files will get different names. A little more testing would be:
find -name '*.jpg' -exec echo bash -c 'mv -i "" "$RANDOM.jpg"' ;
However, this will put all files to the current dir. Maybe using -execdir is an option?
find -name '*.jpg' -execdir bash -c 'mv -i "" "$RANDOM.jpg"' ;
However, make a backup, be careful about your data and so on. Mass actions with find are a sharp instrument. I take no responsibility.
AFAIK dashes have no horses in this race.
There is no case for rename, because you may just do it with mv.
find -name '*.jpg' -exec bash -c 'mv -i "" "$RANDOM.jpg"' ;
mv -i means interactive. It asks before overwriting.
This is not testet in depth, just ad hoc, to make sure files will get different names. A little more testing would be:
find -name '*.jpg' -exec echo bash -c 'mv -i "" "$RANDOM.jpg"' ;
However, this will put all files to the current dir. Maybe using -execdir is an option?
find -name '*.jpg' -execdir bash -c 'mv -i "" "$RANDOM.jpg"' ;
However, make a backup, be careful about your data and so on. Mass actions with find are a sharp instrument. I take no responsibility.
AFAIK dashes have no horses in this race.
answered Feb 6 at 17:01
user unknown
4,80622151
4,80622151
Especially the third one is perfect, but the purpose of this whole thing is still obscure. To me, at least.
â PerlDuck
Feb 6 at 17:14
This is the right approach IMHO except that you might considerbash -c 'for f; do mv -i -- "$f" "$RANDOM.jpg"; done' bash +
(for efficiency, and to avoid expansion of theinside the command string). The OP could also consider using something like
"$(mktemp --suffix=.jpg --tmpdir=. XXXXXX)"
in place of$RANDOM
since the latter is not guaranteed to be unique.
â steeldriver
Feb 6 at 17:17
Did you test for efficiency? What did you get? IMHO, this action will be harddrive limited, so trying to read and write at the same time might end up in worse performance. It's an additional layer of complexity, and I've learned to just do it right, and later care for performance, and only, if necessary. But I'm very interested in numbers, so if you have made some measurements, be invited! Because I hear such advice often, in connection with find ";" and +.
â user unknown
Feb 6 at 17:21
add a comment |Â
Especially the third one is perfect, but the purpose of this whole thing is still obscure. To me, at least.
â PerlDuck
Feb 6 at 17:14
This is the right approach IMHO except that you might considerbash -c 'for f; do mv -i -- "$f" "$RANDOM.jpg"; done' bash +
(for efficiency, and to avoid expansion of theinside the command string). The OP could also consider using something like
"$(mktemp --suffix=.jpg --tmpdir=. XXXXXX)"
in place of$RANDOM
since the latter is not guaranteed to be unique.
â steeldriver
Feb 6 at 17:17
Did you test for efficiency? What did you get? IMHO, this action will be harddrive limited, so trying to read and write at the same time might end up in worse performance. It's an additional layer of complexity, and I've learned to just do it right, and later care for performance, and only, if necessary. But I'm very interested in numbers, so if you have made some measurements, be invited! Because I hear such advice often, in connection with find ";" and +.
â user unknown
Feb 6 at 17:21
Especially the third one is perfect, but the purpose of this whole thing is still obscure. To me, at least.
â PerlDuck
Feb 6 at 17:14
Especially the third one is perfect, but the purpose of this whole thing is still obscure. To me, at least.
â PerlDuck
Feb 6 at 17:14
This is the right approach IMHO except that you might consider
bash -c 'for f; do mv -i -- "$f" "$RANDOM.jpg"; done' bash +
(for efficiency, and to avoid expansion of the
inside the command string). The OP could also consider using something like "$(mktemp --suffix=.jpg --tmpdir=. XXXXXX)"
in place of $RANDOM
since the latter is not guaranteed to be unique.â steeldriver
Feb 6 at 17:17
This is the right approach IMHO except that you might consider
bash -c 'for f; do mv -i -- "$f" "$RANDOM.jpg"; done' bash +
(for efficiency, and to avoid expansion of the
inside the command string). The OP could also consider using something like "$(mktemp --suffix=.jpg --tmpdir=. XXXXXX)"
in place of $RANDOM
since the latter is not guaranteed to be unique.â steeldriver
Feb 6 at 17:17
Did you test for efficiency? What did you get? IMHO, this action will be harddrive limited, so trying to read and write at the same time might end up in worse performance. It's an additional layer of complexity, and I've learned to just do it right, and later care for performance, and only, if necessary. But I'm very interested in numbers, so if you have made some measurements, be invited! Because I hear such advice often, in connection with find ";" and +.
â user unknown
Feb 6 at 17:21
Did you test for efficiency? What did you get? IMHO, this action will be harddrive limited, so trying to read and write at the same time might end up in worse performance. It's an additional layer of complexity, and I've learned to just do it right, and later care for performance, and only, if necessary. But I'm very interested in numbers, so if you have made some measurements, be invited! Because I hear such advice often, in connection with find ";" and +.
â user unknown
Feb 6 at 17:21
add a comment |Â
up vote
0
down vote
You're unclear about how you want files to renamed. As far as which files to rename you can use find
to match all files according you the desired pattern containing a dash:
find [PATH...] -type f -name '*-*' | prename EXPR
If you want to match directories too you need to use the -depth
option:
find [PATH...] -depth -name '*-*' | prename EXPR
1
I think the OP is mistakenly attributing therename
error to the fact that their directories have dashes in their names
â steeldriver
Feb 6 at 16:16
add a comment |Â
up vote
0
down vote
You're unclear about how you want files to renamed. As far as which files to rename you can use find
to match all files according you the desired pattern containing a dash:
find [PATH...] -type f -name '*-*' | prename EXPR
If you want to match directories too you need to use the -depth
option:
find [PATH...] -depth -name '*-*' | prename EXPR
1
I think the OP is mistakenly attributing therename
error to the fact that their directories have dashes in their names
â steeldriver
Feb 6 at 16:16
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You're unclear about how you want files to renamed. As far as which files to rename you can use find
to match all files according you the desired pattern containing a dash:
find [PATH...] -type f -name '*-*' | prename EXPR
If you want to match directories too you need to use the -depth
option:
find [PATH...] -depth -name '*-*' | prename EXPR
You're unclear about how you want files to renamed. As far as which files to rename you can use find
to match all files according you the desired pattern containing a dash:
find [PATH...] -type f -name '*-*' | prename EXPR
If you want to match directories too you need to use the -depth
option:
find [PATH...] -depth -name '*-*' | prename EXPR
edited Feb 6 at 16:19
answered Feb 6 at 15:47
![](https://i.stack.imgur.com/E0SEH.png?s=32&g=1)
![](https://i.stack.imgur.com/E0SEH.png?s=32&g=1)
David Foerster
26.5k1362106
26.5k1362106
1
I think the OP is mistakenly attributing therename
error to the fact that their directories have dashes in their names
â steeldriver
Feb 6 at 16:16
add a comment |Â
1
I think the OP is mistakenly attributing therename
error to the fact that their directories have dashes in their names
â steeldriver
Feb 6 at 16:16
1
1
I think the OP is mistakenly attributing the
rename
error to the fact that their directories have dashes in their namesâ steeldriver
Feb 6 at 16:16
I think the OP is mistakenly attributing the
rename
error to the fact that their directories have dashes in their namesâ steeldriver
Feb 6 at 16:16
add a comment |Â
up vote
0
down vote
I just tried this on sub-folders with a dash in their name, and it worked.
Renaming Portions of Filenames Recusively in Linux/Ubuntu
To rename files, you use the find command in conjunction with the rename command like this:
find -type f -execdir rename 's/OriginalText/NewText/' *.jpg '' ;
So if you want to replace all the dashes "-" in all the jpg filenames with underscores "_" then you would enter:
find -type f -execdir rename 's/-/_/' *.jpg '' ;
add a comment |Â
up vote
0
down vote
I just tried this on sub-folders with a dash in their name, and it worked.
Renaming Portions of Filenames Recusively in Linux/Ubuntu
To rename files, you use the find command in conjunction with the rename command like this:
find -type f -execdir rename 's/OriginalText/NewText/' *.jpg '' ;
So if you want to replace all the dashes "-" in all the jpg filenames with underscores "_" then you would enter:
find -type f -execdir rename 's/-/_/' *.jpg '' ;
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I just tried this on sub-folders with a dash in their name, and it worked.
Renaming Portions of Filenames Recusively in Linux/Ubuntu
To rename files, you use the find command in conjunction with the rename command like this:
find -type f -execdir rename 's/OriginalText/NewText/' *.jpg '' ;
So if you want to replace all the dashes "-" in all the jpg filenames with underscores "_" then you would enter:
find -type f -execdir rename 's/-/_/' *.jpg '' ;
I just tried this on sub-folders with a dash in their name, and it worked.
Renaming Portions of Filenames Recusively in Linux/Ubuntu
To rename files, you use the find command in conjunction with the rename command like this:
find -type f -execdir rename 's/OriginalText/NewText/' *.jpg '' ;
So if you want to replace all the dashes "-" in all the jpg filenames with underscores "_" then you would enter:
find -type f -execdir rename 's/-/_/' *.jpg '' ;
edited Feb 7 at 17:59
answered Feb 7 at 3:02
SunnyDaze
82128
82128
add a comment |Â
add a comment |Â
4
What exactly is the intent of
$RANDOM.jpg $RANDOM.jpg
?rename
expects a valid Perl expression telling it what to rename the files from and toâ steeldriver
Feb 6 at 13:58
I don't know because i've found it in the web. So how i can rename to a random name all .jpg files in all subdirs? Thanks for your answer, steeldriver
â Jane Farrow
Feb 6 at 14:01
2
Are you sure you want to rename all your Jpegs to something like
XrUg2oCLIIoBGwH.jpg
,l9OD0lus8Ft1LJ9.jpg
, and73k9qXms3rIH2Mr.jpg
? I'm looking forward to reading a question about getting rid of files with weird names then.â PerlDuck
Feb 6 at 14:17
1
Maybe the sybtax of the find should be
find -name '*.jpg' -exec rename $RANDOM.jpg ;
That will rename each .jpg file found () to the content of $RANDOM with .jpg added.
â Soren A
Feb 6 at 14:34
4
@SorenA That will rename all files to the same name because
$RANDOM
gets evaluated only once.â PerlDuck
Feb 6 at 14:40