LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-12-2008, 11:45 PM   #1
wordsmithy
LQ Newbie
 
Registered: May 2008
Posts: 1

Rep: Reputation: 0
how to convert filename mojibake back into original encoding??


I used the Japanese version of slackware to back up all of my japanese-encoded files onto an external device but when I try to access those files they are not in the encoding windows or mac are expecting so the filenames show up as garbage(the contents are intact and okay, just the filenames are messed up). If I access the device from slax, it can read them so I think the issue is that slax/linux in general is by default in EUC or UTF-8 and windows and mac are looking for shift-JIS? I'm not an expert on this and it usually "just works" so I am looking for the easiest way to convert or have these files recognized outside of a linux environment. The original files can't be recopied, either, so I am stuck. Any suggestions?
 
Old 05-13-2008, 02:13 AM   #2
hro
LQ Newbie
 
Registered: Jan 2008
Distribution: OpenSuse 10.3, SLED 10 SP2, Ubuntu 8.04 and 9.04
Posts: 23

Rep: Reputation: 15
You can use 'recode' command within script to change encoding of the filenames. You should make some testing and read 'info recode' or at least 'man recode'. You will need more complicated script in order to traverse directories. Here is example scripts to rename files using ISO-8859-1 encoding and to rename them back using default encoding.

Code:
~/xDocs/test> ll *.txt
-rw-r--r-- 1 hro users 0 2008-05-13 09:22 ÄÖÜ.txt
-rw-r--r-- 1 hro users 0 2008-05-13 09:13 öäå.txt
~/xDocs/test> cat utf2iso.sh
#!/bin/bash
# hro, 2008-05-13
#
for fin in *.txt
        do (
        fout=$(ls $fin | recode ISO-8859-1)
        mv $fin $fout
        ) done

~/xDocs/test> utf2iso.sh
~/xDocs/test> ll *.txt
-rw-r--r-- 1 hro users 0 2008-05-13 09:13 öäå.txt
-rw-r--r-- 1 hro users 0 2008-05-13 09:22 Ã?Ã?Ã?.txt
Code:
~/xDocs/test> cat iso2utf.sh
#!/bin/bash
# hro, 2008-05-13
#
for fin in *.txt
        do (
        fout=$(ls $fin | recode ..ISO-8859-1)
        mv $fin $fout
        ) done

~/xDocs/test> iso2utf.sh
~/xDocs/test> ll *.txt
-rw-r--r-- 1 hro users 0 2008-05-13 09:22 ÄÖÜ.txt
-rw-r--r-- 1 hro users 0 2008-05-13 09:13 öäå.txt
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert static library (Filename.a) to dynamic shared object (filename.so) afx2029 Linux - Software 4 08-17-2007 06:07 AM
converting file encoding (batch files) with same output filename yuubouna Linux - Newbie 1 01-14-2007 08:32 PM
Convert encoding through subdirectories? dl7und Linux - Software 2 04-16-2006 01:06 AM
Character encoding problem for filename in ubuntu xenthos Linux - General 1 03-22-2006 12:59 PM
How to know encoding used for filename synna Programming 1 12-22-2004 09:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration