Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Filename case collision
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
pholthau
Guru
Guru


Joined: 27 Nov 2005
Posts: 361
Location: Bielefeld, Germany

PostPosted: Sat Oct 25, 2008 11:21 am    Post subject: Filename case collision Reply with quote

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
View user's profile Send private message
nurachi
Tux's lil' helper
Tux's lil' helper


Joined: 16 May 2008
Posts: 92
Location: Paris

PostPosted: Sat Oct 25, 2008 1:05 pm    Post subject: Reply with quote

Something like this?
Code:
find directory -iname filename -print
Back to top
View user's profile Send private message
pholthau
Guru
Guru


Joined: 27 Nov 2005
Posts: 361
Location: Bielefeld, Germany

PostPosted: Sat Oct 25, 2008 1:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
pholthau
Guru
Guru


Joined: 27 Nov 2005
Posts: 361
Location: Bielefeld, Germany

PostPosted: Sat Oct 25, 2008 1:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
nurachi
Tux's lil' helper
Tux's lil' helper


Joined: 16 May 2008
Posts: 92
Location: Paris

PostPosted: Sat Oct 25, 2008 2:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
pholthau
Guru
Guru


Joined: 27 Nov 2005
Posts: 361
Location: Bielefeld, Germany

PostPosted: Sat Oct 25, 2008 3:30 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum