rename script won't change uppercase to lowercase on fat32
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
rename script won't change uppercase to lowercase on fat32
I'm not sure if the reason it's not working is because it's a fat32 partition, but it seems to work ok on the reiserfs partitions I've got. This is the script:
Code:
#! /bin/sh
# converting space to underscores ({i// /_}) and uppercase to lowercase
# (tr "[:upper:]" "[:lower:]")
for i in *
do mv "$i" "$(echo ${i// /_} | tr "[:upper:]" "[:lower:]")"
done
if I try a manual mv, I get the same error:
Code:
mv: cannot move `Summer_2002' to a subdirectory of itself, `summer_2002/Summer_2002'
for a directory, and
Code:
mv: `Seignosse 001.avi' and `seignosse 001.avi' are the same file
for a file.
Is this because it's fat32? Is there any way around this?
Yes druuna fat32 does not make any distiction between upper and lowercase file names. NTFS does but thats because its a non dos filesystem. This is indeed a file system limitation.
from that other thread I found, it seems that if you mount the drive in a particular manner, it's possible to get it to distinguish between upper and lowercase. This is the reply to the OPs question in the other thread (by the OP I might add!...):
I can tell it to rename a file called "Test" to "Test.temp" without it complaining. Ok, good. I can then tell it to rename that "Test.temp" file to "test" (note lowercase first letter), and it holds the case. It seems that only by going through this intermediate stage of calling it something different can I get it to rename a file to lowercase letters.
So, with that in mind, I've tried the following:
Code:
#! /bin/sh
# testing some ideas for renaming scripts...
# remove all spaces from the filenames first
for i in *
do mv "$i" "${i// /_}"
done
# create a list of the directory contents, and turn it into a lowercase file list
ls -1 $PWD | tr "*/" " " | tr "A-Z" "a-z" > $PWD/list
# then rename all the folders in the current directory to original_name.temp
for i in $PWD/*
do mv "$i" "$i.temp"
done
# then, rename the files called original_name.temp to the lowercase name from the list file
#for i in `ls -1 | tr "*/" " "`
# do mv "$i" "$(cat list.temp)"
#done
# try to rename the files from the list.temp file using a foreach loop
#for i in *
# do foreach j=`cat list.temp`
# mv "$i" "$j"
# done
#done
# or create a new variable which contains the list of the cat'ed list.temp.
# For this, you'll need two loops
#for i in *
# for j in `cat list.temp`
# do mv "$i" "$j"
# done
#done
# multiple do's within a for...
for i in *
do NAME=`cat list.temp` && {
mv $i $NAME
}
done
what I'm trying to do is use the contents of a file (list.temp) as the input for the mv command i.e. the new filename. However, what happens when I cat the contents of list.temp in the loop is the first file the for loop comes across gets renamed to all the files in the list, so rather than having say 10 individial file, I get one file renamed with all 10 original filnames, separated by \n. I can't for the life of me figure out how to get it to just use one line of the list.temp file for each cycle through the loop.
I thought maybe a "while" might need to be involved at some point...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.