[SOLVED] "ToLower" file extension
Forum rules
LMDE 2 has reached end of support as of 1-1-2019
LMDE 2 has reached end of support as of 1-1-2019
[SOLVED] "ToLower" file extension
I've had a problem in LMDE2 for a while, but never bothered to ask about it, and always just work around it.
However, I'd like to find an answer:
I have a folder full of a mix of .jpg and .JPG files. While trying to create a quick bash script to run on *.jpg, I found that when I try to mv or rename a .JPG file to a .jpg file - I receive an error that the file already exists. I can't find a way to rename the capital JPG extensions to lowercase jpg extensions without specifying a different destination filename. (Even using the GUI)
I'm sure the answer is obvious, but I haven't been successful in my on-line queries to find an answer of how "tolower" the file extensions. (To be clear, I've found scripts which claim to perform the renaming of the extensions, but they fail with the same error.)
Again, I've always just worked around this by renaming the destination files, but surely I'm missing an easier way.
Thanks,
Fuzzy
However, I'd like to find an answer:
I have a folder full of a mix of .jpg and .JPG files. While trying to create a quick bash script to run on *.jpg, I found that when I try to mv or rename a .JPG file to a .jpg file - I receive an error that the file already exists. I can't find a way to rename the capital JPG extensions to lowercase jpg extensions without specifying a different destination filename. (Even using the GUI)
I'm sure the answer is obvious, but I haven't been successful in my on-line queries to find an answer of how "tolower" the file extensions. (To be clear, I've found scripts which claim to perform the renaming of the extensions, but they fail with the same error.)
Again, I've always just worked around this by renaming the destination files, but surely I'm missing an easier way.
Thanks,
Fuzzy
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
- catweazel
- Level 19
- Posts: 9763
- Joined: Fri Oct 12, 2012 9:44 pm
- Location: Australian Antarctic Territory
Re: "ToLower" file extension
Post an example command that you use when you get this message, along with some file names it applies to.
Please enclose the results between
[ⅽode]
and [/ⅽode]
code markers by selecting </>
from the mini toolbar above the textbox where you type your reply."There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
Re: "ToLower" file extension
Thanks for the quick response!
Literally, using the GUI I can right-click a file named File.JPG and change the name to File.jpg, and I will receive an error.
If I use a command line like:
I receive the following errors:
This causes some problems in my scripts, as they perform loops based on the number of .jpg files - and I realize there are ways around this, but it is odd to me that I'm unable to rename the file extension to a lower-case version of the same thing.
EDIT: It is important to note that the bash scripts are sensitive about lowercase vs uppercase extensions. For instance, I'll run a script which starts with something like It then skips any .JPG files. So my plan was to rename the JPG to jpg, then run the script.
Literally, using the GUI I can right-click a file named File.JPG and change the name to File.jpg, and I will receive an error.
If I use a command line like:
Code: Select all
rename 's/\.JPG$/.jpg/' *.JPG
Code: Select all
DSC_0396.JPG not renamed: DSC_0396.jpg already exists
DSC_0409.JPG not renamed: DSC_0409.jpg already exists
DSC_0421.JPG not renamed: DSC_0421.jpg already exists
DSC_0530.JPG not renamed: DSC_0530.jpg already exists
DSC_0545.JPG not renamed: DSC_0545.jpg already exists
DSC_0559.JPG not renamed: DSC_0559.jpg already exists
DSC_0561.JPG not renamed: DSC_0561.jpg already exists
EDIT: It is important to note that the bash scripts are sensitive about lowercase vs uppercase extensions. For instance, I'll run a script which starts with something like
Code: Select all
for i in *.jpg
- AZgl1800
- Level 20
- Posts: 11145
- Joined: Thu Dec 31, 2015 3:20 am
- Location: Oklahoma where the wind comes Sweeping down the Plains
- Contact:
Re: "ToLower" file extension
The Sledge Hammer approach would be to copy all of the *.JPG files to a separate HDD while renaming them in the process.
then delete the *.JPG files, and copy the renamed *.jpg files back
you would have to sort by Extension to make this easier though, to delete the JPG files.
then delete the *.JPG files, and copy the renamed *.jpg files back
you would have to sort by Extension to make this easier though, to delete the JPG files.
- catweazel
- Level 19
- Posts: 9763
- Joined: Fri Oct 12, 2012 9:44 pm
- Location: Australian Antarctic Territory
Re: "ToLower" file extension
That's because you're using the wrong perl expression in the rename. It's years since I last looked at perl but I think you need the y rather than the s operator.
rename 'y/\.JPG$/.jpg/' *.JPG
Anyway, this will do it for you using mv:
Code: Select all
#!/bin/bash
for fn in *.JPG
do
mv "$fn" "${fn%.JPG}.jpg"
done
Last edited by catweazel on Fri Sep 07, 2018 11:32 pm, edited 2 times in total.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
- catweazel
- Level 19
- Posts: 9763
- Joined: Fri Oct 12, 2012 9:44 pm
- Location: Australian Antarctic Territory
Re: "ToLower" file extension
That's completely impractical.AZgl1500 wrote: ⤴Fri Sep 07, 2018 11:29 pm The Sledge Hammer approach would be to copy all of the *.JPG files to a separate HDD while renaming them in the process.
then delete the *.JPG files, and copy the renamed *.jpg files back
you would have to sort by Extension to make this easier though, to delete the JPG files.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
Re: "ToLower" file extension
Doesn't make a difference. y/ is a transform and s/ is a replace, same result in this case. I'll agree y/ is preferable for this kind of stuff insofar as you can mess up less if you make a mistake.
- catweazel
- Level 19
- Posts: 9763
- Joined: Fri Oct 12, 2012 9:44 pm
- Location: Australian Antarctic Territory
Re: "ToLower" file extension
I'm sure you're probably correct. I can't be bothered to re-learn perl
The mv example will work though.
EDIT: I tested
rename "y...
and you are indeed wrong.Before:
Code: Select all
-rw-rw-r-- 1 boot boot 448208 Sep 8 13:38 'DSCN0008 (1).JPG'
-rw-rw-r-- 1 boot boot 448208 Sep 8 13:38 'DSCN0008 (2).JPG'
-rw-rw-r-- 1 boot boot 448208 Sep 8 13:38 'DSCN0008 (3).JPG'
-rw-rw-r-- 1 boot boot 448208 Sep 8 13:38 'DSCN0008 (4).JPG'
-rw-rw-r-- 1 boot boot 448208 Sep 8 13:38 'DSCN0008 (5).JPG'
-rw-rw-r-- 1 boot boot 448208 Sep 8 13:38 DSCN0008.JPG
rename 'y/\.JPG$/.jpg/' *.JPG
:
Code: Select all
-rw-rw-r-- 1 boot boot 448208 Sep 8 13:38 'DSCN0008 (1).jpg'
-rw-rw-r-- 1 boot boot 448208 Sep 8 13:38 'DSCN0008 (2).jpg'
-rw-rw-r-- 1 boot boot 448208 Sep 8 13:38 'DSCN0008 (3).jpg'
-rw-rw-r-- 1 boot boot 448208 Sep 8 13:38 'DSCN0008 (4).jpg'
-rw-rw-r-- 1 boot boot 448208 Sep 8 13:38 'DSCN0008 (5).jpg'
-rw-rw-r-- 1 boot boot 448208 Sep 8 13:38 DSCN0008.jpg
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
Re: "ToLower" file extension
Hi folks. Thanks for your time and input.
I've ended up (short term) simply running a script to rename them to .png, then to .jpg. Not a solution, but a work-around.
Catweazel - I copy/pasted your script into a bash named catweazel.bash, but when I run it, I get the same results as I posted above.
(which contains:
and outputs:
As evidenced by my post, I'm not good at these things, so if there is something obvious which I could have missed which would cause these problems, start there because I probably missed it. ;^)>>>
Thanks again for your efforts to help me.
I've ended up (short term) simply running a script to rename them to .png, then to .jpg. Not a solution, but a work-around.
Catweazel - I copy/pasted your script into a bash named catweazel.bash, but when I run it, I get the same results as I posted above.
Code: Select all
bash catweazel.bash
Code: Select all
#!/bin/bash
for fn in *.JPG
do
mv "$fn" "${fn%.JPG}.jpg"
done
Code: Select all
mv: ‘DSC_0200.JPG’ and ‘DSC_0200.jpg’ are the same file
mv: ‘DSC_0209.JPG’ and ‘DSC_0209.jpg’ are the same file
mv: ‘DSC_0211.JPG’ and ‘DSC_0211.jpg’ are the same file
mv: ‘DSC_0230.JPG’ and ‘DSC_0230.jpg’ are the same file
mv: ‘DSC_0238.JPG’ and ‘DSC_0238.jpg’ are the same file
Thanks again for your efforts to help me.
- catweazel
- Level 19
- Posts: 9763
- Joined: Fri Oct 12, 2012 9:44 pm
- Location: Australian Antarctic Territory
Re: "ToLower" file extension
How bizarre. Both examples I gave were tested and work fine for me.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
Re: "ToLower" file extension
I agree. It has me scratching my head!How bizarre. Both examples I gave were tested and work fine for me.
For now, I'll continue using my work-around of renaming the files to png and then back to jpg, as this project is fairly small, and just for my own personal website...but over the last year or two, I've had to work around the issue a handful of times, so I thought I'd throw it out here for you smart folks and see if anyone else had the problem, or knew of a solution.
Thanks again for the help!
Fuzzy
Re: "ToLower" file extension
You are doing this on a non-case sensitive file system like FAT32 is the only logical explanation I can think of.Fuzzy wrote: ⤴Fri Sep 07, 2018 11:56 pm and outputs:Code: Select all
mv: ‘DSC_0200.JPG’ and ‘DSC_0200.jpg’ are the same file mv: ‘DSC_0209.JPG’ and ‘DSC_0209.jpg’ are the same file mv: ‘DSC_0211.JPG’ and ‘DSC_0211.jpg’ are the same file mv: ‘DSC_0230.JPG’ and ‘DSC_0230.jpg’ are the same file mv: ‘DSC_0238.JPG’ and ‘DSC_0238.jpg’ are the same file
Last edited by gm10 on Sat Sep 08, 2018 12:20 am, edited 1 time in total.
- catweazel
- Level 19
- Posts: 9763
- Joined: Fri Oct 12, 2012 9:44 pm
- Location: Australian Antarctic Territory
Re: "ToLower" file extension
You mean "wouldn't", yet both examples I gave the OP work fine for me here. As for your .sig, mine gets me out of any predicament
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
- smurphos
- Level 18
- Posts: 8501
- Joined: Fri Sep 05, 2014 12:18 am
- Location: Irish Brit in Portugal
- Contact:
Re: "ToLower" file extension
This works without having to rename any extension...Fuzzy wrote: ⤴Fri Sep 07, 2018 11:07 pm For instance, I'll run a script which starts with something likeIt then skips any .JPG files. So my plan was to rename the JPG to jpg, then run the script.Code: Select all
for i in *.jpg
for i in *.jpg *.JPG *.jpeg *.JPEG
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Re: "ToLower" file extension
No U. I even agreed with you that y/ is preferable, so I'm really confused about this misunderstanding.
At the same time I really don't care one bit, so let's carry on. You can now point to FAT32 and then say I denied that previously.
- catweazel
- Level 19
- Posts: 9763
- Joined: Fri Oct 12, 2012 9:44 pm
- Location: Australian Antarctic Territory
Re: "ToLower" file extension
Doesn't make a difference. y/ is a transform and s/ is a replace, same result in this case.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
Re: "ToLower" file extension
and...if there is something obvious which I could have missed which would cause these problems, start there because I probably missed it.
Yep! It is an old SAMBA share on an old machine that has been around far too long. Not sure of the filesystem being used, but that's the cause. I tried to copy some of the photos/files in question to my local machine, and tried again - everything works fine.You are doing this on a non-case sensitive file system like FAT32 is the only logical explanation I can think of.
Sorry for wasting everyone's time, but I sure appreciate the help, and I'll remember this next time. (I'll also be checking/changing some configurations around to avoid this issue in the future.)
Marking as SOLVED.
Thanks,
Fuzzy