1

Background :

You can skip this section, if you are not interested in.

I usually backup my MicroSD card of my cell phone, with command sudo dd if=/dev/sdc1 of=~/Document/Cell\ Phone\ Files/MicroSD_Backup/$(date +%y-%m-%d).img after connecting the MicroSD card to my PC with the Card Reader.

There is only one partition on my MicroSD card and it's filesystem is fat32. And the default encoding of it is GBK. So, Chinese filename are encoded with GBK, while English filename are encoded with ASCII.

After I having made the latest image of the MicroSD card, I want to format it and delete some useless files in the latest image.

Description :

The img file contains files with gbk filename and ascii filename, while the default encoding of my PC is UTF-8. I want to convert those GBK filenames to UTF-8, but I concern about those files with an ASCII filename will become garbled with running command convmv --notest -f gbk -t utf-8 * in the image file mounted directory.

Question :

Is it possible to find out those files with gbk filename, and pipe their path to the convmv command? So, those files with ASCII filenames can survive.

  • Have you tried looking at iconv? – Yaron Jun 19 '16 at 11:14
  • @Yaron It seems that iconv only deal with text content. I just want to convent filenames. – TJM Jun 19 '16 at 11:28
  • ASCII is a subset of GBK, so converting all of them as GBK should be fine. – Siyuan Ren Jun 19 '16 at 11:29
  • Are there any other encodings? If not you could use isutf8 from Joey Hess' moreutils to selectively only convert those that aren't UTF-8. – phk Jun 19 '16 at 11:31
  • Well, sort of... stackoverflow.com/questions/9930484/… – Yaron Jun 19 '16 at 11:33
1

Thanks for @SiyuanRen 's suggestion. convmv can deal with the mess situation keeping ascii unchanged which avoid being garbled.

Command convmv -f gbk -t utf8 * works fine under this circumstance.

By the way, another solution is use -o loop,utf8 while mounting image files, or just use udisksctl which can automatically deal with filename encoding.

P.S. the whole way to use udisksctl is

# losetup --fine --show /path-to-img-file
$ udisksctl -b /the-loop-file-showed-after-former-command

Then, input your account's password, and it will show you where it is mounted/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.