Preserving UTF-8 Encoding when Copying Files between Directories

Posted on 2009-04-24
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
    LVL 11

    Expert Comment

    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

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

    Expert Comment

    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

    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

    So in essence my response regarding preserve was correct yes?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
    Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now