9

I have a problem with some files in linux (Ubuntu) terminal, with accents in the names. For example:

$ ls dir/
criação.png 

So, the terminal returns that file, so it exists. Now lets look if the file exists, with this simple command:

$ [ -f criação.png ] &&  echo "File Exist" || echo "Not Exist"
Not Exist

As you can see, "Not Exist". Now, i have the same folder and file on OSX, then I run the same command and it returns this:

$ [ -f criação.png ] &&  echo "File Exist" || echo "Not Exist"
File Exist

I know a little about locale:

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE=en_US.UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8" 
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

On linux, "Not Exist", on OSX, "File Exist"... Someone, know how to fix that?

Maybe these can help:
http://nedbatchelder.com/blog/201106/filenames_with_accents.html
http://www.ruby-forum.com/topic/279105

UPDATE - Solution

I finally found a solution to that problem. You need to rename your files from NFD to NFC, here is the command to fix all files:

cd dir/
convmv -r -i -f utf8 -t utf8 --nfc --notest .

Source: http://blog.hbis.fr/2010/08/30/macox-utf8_filenames_normalization/

  • My problem is with nginx too. Ex: `2012/11/08 17:05:34 [error] 12102#0: *128 open() "/usr/share/nginx/www/wp-content/uploads/2012/09/celular-inclusão-digital.png" failed (2: No such file or directory), client: 66.249.76.145, server: site.com, request: "GET /wp-content/uploads/2012/09/celular-inclus%C3%A3o-digital.png HTTP/1.1", host: "site.com"` – mateussouzaweb Nov 08 '12 at 17:09
  • 1
    The solution is correct (MacOS uses NFD but pretty much everything else uses NFC, causing compatibility problems when MacOS is involved), but you should post it as an answer. Your answer is more correct than the one you accepted! – Celada Nov 08 '12 at 22:58
  • `convmv -r -f iso8859-1 -t utf8 --nfc --notest .` It fix my filenames with accent uploaded by SFTP from Windows to Linux. – Jose Nobile Mar 13 '13 at 19:42

1 Answers1

1

One of the reasons might be the file name uses a different unicode normalization form of characters with combining marks than you use to type the name. See Unicode Equivalence.

choroba
  • 231,213
  • 25
  • 204
  • 289
  • Yeah, i tried some commands, then i accidentaly found a "trick" to work: `mv criac<0327>a<0303>o.png criação.png` Now the file exist. Is something about NFC e NFD – mateussouzaweb Nov 08 '12 at 18:41