Jump to content

Recommended Posts

Posted

Ive got the following bash script:

 

#!/bin/bash

for x in `ls`
 do
 if [ ! -f $x ]; then
   continue
   fi
 lc=`echo $x  | tr '[A-Z]' '[a-z]'`
 if [ $lc != $x ]; then
   mv -i $x $lc
 fi
 done

 

Which converts file-names to lowercase.

 

The problem I'm having, is the folder I am trying to run it against, is a network share which the host file system is NTFS.

 

The script is failing saying the original and new filename are the same. Is this because NTFS doesn't recognize different cases, or is there something wrong with the script?

 

Is there an equivalent script I could run on the windows host to achieve the same thing?

Posted
could you do it as a 2 stage script (yes messy) 1st stage renames as lower case but adds say an _ at the end of the filename 2nd stage renames without the _
Posted (edited)

I think that NTFS doesn't distinguish between names with different case when performing operations such as open or rename.

 

Your script lacks double-quotes, which you will need when dealing with filenames containing spaces. I've edited it below to add them (un-tested.)

 

Actually, I've just realised that this could be a unicode problem. Try replacing the the tr line with

lc="$(echo "$x"  | tr '[:upper:]' '[:lower:]'`)"

One simple way to get a better idea of what is going on would be to add "echo " at the start of the line which does the move, like this:

echo mv -i "$x" "$lc"

This would show you what the commands were going to be, without executing them.

 

#!/bin/bash

for x in `ls`
do
 if [ ! -f "$x" ]; then
   continue
 fi
 lc="$(`echo "$x"  | tr '[A-Z]' '[a-z]'`)"
 if [ "$lc" != "$x" ]; then
   mv -i "$x" "$lc"
 fi
done

Edited by Eric
typo: s/exciting/executing/
Posted
Also be aware that windows explorer will alter the case of filenames before display in some circumstances. Use the command line to verify if the rename is working.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...