TL;DR Scroll to the end
That's a fantastic question. Thanks for asking it.
It is possible to perform an accent-insensitive search, but not by default, and not automatically, as far as I know. You can find all six of your sample files with this:
find . -name '[[=a=]]'
That's standard POSIX glob notation for all-characters-that-are-like-a-but-maybe-with-an-accent.
So, if you know all of the characters that might have an accented version, you can use the above notation explicitly in your searches. e.g.:
find . -name 'fran[[=c=]]ais' # To match a cedilla
But that's tedious and deeply unsatisfactory.
Note that the [[=a=]]
notation can also be used with characters for which there aren't any accented versions. So [[=k=]]
will match k
.
So I recommend creating a script (accented) that takes a string on the command line, replaces every letter with the [[=x=]]
version of it, and prints out the result, and then you can use that with find. e.g.:
#!/usr/bin/env perl
print join('', map { /\p{Letter}/ ? "[[=$_=]]" : $_ } split //, $ARGV[0]), "\n";
Using that with find might look like:
find . -name "`accented a`"
If you want it to feel automatic, and if you only use find in the most simple way, you could create a shell script (ffind) that combines find and accented:
#!/bin/sh
find "$1" -name "`accented \"$2\"`"
Then you could do:
ffind . a
But that would make it impossible to use find's other predicates.
When you need that, you would have to use the real find and accented explicitly (like above).
Here
A smarter solution is a wrapper around find (ffind) that scans for -name
and -iname
arguments, and effectively applies accented to the following argument, and then executes the resulting modified find command. e.g.:
#!/usr/bin/env perl
use warnings;
use strict;
# ffind - find wrapper that makes -name and -iname accent-insensitive
my @cmd;
while (@ARGV)
{
# Gather command line arguments
push @cmd, shift @ARGV;
# Make -name and -iname arguments accent-insensitive
if ($cmd[-1] =~ /^-i?name$/ && @ARGV)
{
push @cmd, join('', map { /\p{Letter}/ ? "[[=$_=]]" : $_ } split //, shift @ARGV);
}
}
exec 'find', @cmd;
Then you can do to this to find all six of your sample files:
ffind . -name a
Of course, you could call it find and change the 'find'
on the last line to '/usr/bin/find'
, and that would make find accent-insensitive transparently:
find . -name a
Sadly, this entire approach only works on some systems, like Debian 12, but not all. :-(
find . -iregex './[a-z]$'
, but I think this isn't precise enough for what you need"[aà-åĀ-ą]"
can match them, but GNU Find has no support for it. fd does.nocaseglob
(or similar) options behave, becausefind -iname 'glacier' -exec •••
could very well be replaced withfor file in **/(#i)glacier ; do •••