View previous topic :: View next topic |
Author |
Message |
pholthau Guru
Joined: 27 Nov 2005 Posts: 361 Location: Bielefeld, Germany
|
Posted: Sat Oct 25, 2008 11:21 am Post subject: Filename case collision |
|
|
Hi!
Does anyone know an expression for find, a special program or something that detects case collisions in file names?
I want to recursively find files in a directory that would appear as the same file in case insensitive file systems.
Thanks! _________________ The message is Feierei, alder! The message is Gude Laune, alder! [Sven] |
|
Back to top |
|
|
nurachi Tux's lil' helper
Joined: 16 May 2008 Posts: 92 Location: Paris
|
Posted: Sat Oct 25, 2008 1:05 pm Post subject: |
|
|
Something like this?
Code: | find directory -iname filename -print |
|
|
Back to top |
|
|
pholthau Guru
Joined: 27 Nov 2005 Posts: 361 Location: Bielefeld, Germany
|
Posted: Sat Oct 25, 2008 1:08 pm Post subject: |
|
|
The file's name has to be variable, as it should find and print out any file that could cause problems. _________________ The message is Feierei, alder! The message is Gude Laune, alder! [Sven] |
|
Back to top |
|
|
pholthau Guru
Joined: 27 Nov 2005 Posts: 361 Location: Bielefeld, Germany
|
Posted: Sat Oct 25, 2008 1:39 pm Post subject: |
|
|
I think something like this should do it (please give some comments if you find any errors or improvements):
Code: |
#!/bin/bash
folder=$1
for filename in $(find $folder -type f -iname "*");
do
count=$(find $folder -iwholename $filename | wc -l);
if [ $count -gt 1 ]; then
echo "$count: $filename";
fi
done
|
_________________ The message is Feierei, alder! The message is Gude Laune, alder! [Sven] |
|
Back to top |
|
|
nurachi Tux's lil' helper
Joined: 16 May 2008 Posts: 92 Location: Paris
|
Posted: Sat Oct 25, 2008 2:16 pm Post subject: |
|
|
It might work.
But according to find man pages iwolename option is an insensitive alias to path option, so if your system if fully case insensitive (and if you have /USR/Local and /usr/local for example), i'd suggest to change:
Code: | count=$(find $folder -iwholename $filename | wc -l); |
into:
Code: | count=$(find `dirname $filename` -maxdepth 1 -iname `basename $filename` -print|wc -l); |
The -maxdepth 1 option is important if you don't want to find recursively into the subdirectories. |
|
Back to top |
|
|
pholthau Guru
Joined: 27 Nov 2005 Posts: 361 Location: Bielefeld, Germany
|
Posted: Sat Oct 25, 2008 3:30 pm Post subject: |
|
|
Thanks, I didn't have paths in mind. I don't think i've something like /usr /USR. It's mainly about iles like dsc1000.jpg and DSC1000.JPG. or protocol.tex and Protocol.tex Things can get doubled up if you are copying files from/to FAT/NTFS USB sticks to whatever.
EDIT: The above won't work if you have spaces in file names. Better use while instead of for:
Code: |
find "${folder}" -type f -iname "*" | while read filename;
do
#count=$(find "${folder}" -iwholename "${filename}" | wc -l);
count=$(find `dirname "${filename}"` -iname `basename "${filename}"` -print | wc -l);
if [ "${count}" -gt 1 ]; then
echo;
echo "${count}: ${filename}";
else
echo -n ".";
fi
done
|
_________________ The message is Feierei, alder! The message is Gude Laune, alder! [Sven] |
|
Back to top |
|
|
|