Preserving UTF-8 Encoding when Copying Files between Directories

Posted on 2009-04-24
Medium Priority
Last Modified: 2012-05-06
Hi,  I am logged into my webserver as root via SSH

I copied all my html files from one directory to another

      \cp -pRf /development/* /production

once finished, utf-8 character encoding got messed up.

when i view them on my production website, the special chars show as "?".  Oddly though it still displays fine in IE.   Just not Mozilla.

both domains are on the same webserver

as a test, i downloaded one of the files via FTP, opened it, saved it as UTF-8 and re-uploaded it.  it displays fine.

So, it looks like somehow during the copy procedure i lose the UTF-8 encoding.

Question by:MarkDJordan
  • 3
  • 2
LVL 11

Expert Comment

ID: 24227395
See if adding the --preserve switch to cp resolves the problem.

              preserve   the   specified   attributes   (default:  mode,owner-
              ship,timestamps), if possible  additional  attributes:  context,
              links, all

Author Comment

ID: 24232354
I used the -p switch, which I thought WAS preserve.  No?
LVL 11

Expert Comment

ID: 24232715
Yes, also you can try the -c switch as well.

Also, another possibility exists. By any chance is the source directory from a mounted disk? Sometimes if using NFS or Samba, character encoding can be corrupted.

A good test is to try to copy a single one of these files without using the -r -R recursive switches, and check if the encoding got corrupted.

Please check those aspects and post back to me so I can further assist you.

Thanks and regards,

K Black

Accepted Solution

MarkDJordan earned 0 total points
ID: 24235647
Seems like what i posted here is not really the issue at all.  I just did another test with just -p and it works fine.  only on occasion does it not work (where it displays ok in dev but not ok in prod).  it must have something to do with the files themselves and how they were originally saved and not with the copy process.  Closing this ticket.  Thanks for your suggestions nonetheless.

LVL 11

Expert Comment

ID: 24236118
So in essence my response regarding preserve was correct yes?

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question