Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I encountered something extremely strange today.

Here's what happened: I wrote a short Python script (to check the connectivity to a host) at work using PyDev. I transferred it from my Windows 7 laptop to a Ubuntu workstation via a thumb drive, and the file would appear as a bunch of gibberish. I tried re-saving and renaming the file, but that did not help. I tried viewing the file on another Ubuntu workstation, and the same thing happened. This has not affected any of my other Python files. I doubt the problem is with my thumb drive because I can read off it perfectly on the laptop.

I eventually decided to e-mail the file to myself, and that solved the problem. Does anyone know what may have happened?

share|improve this question
"Gibberish"? It'd help to include a sample of what you see. – Wyzard Jan 23 '13 at 2:07
I'll post a screenshot when I get to work tomorrow morning. – Danny Chia Jan 23 '13 at 5:57
Strange, I made a few changes to the Python file, and it no longer appears as gibberish. Maybe a sector on the thumb drive was corrupted in a way such that it was only unreadable on Ubuntu. Who knows? – Danny Chia Jan 24 '13 at 0:49

Based on the information you provided I suspect this might have to with the difference in line endings used in *nix and Windows. Check out this page on Wikipedia.

You can confirm if the line ending is the causing the problem by inspecting it using an utility that can dump the ascii characters. On Ubuntu you can use hexdump

hexdump <filename> 

And here's an example that illustrates the difference in line endings between the two systems. The input file is a simple text file named sample.txt with the words line1 and line2 on separate lines

$ cat sample.txt

Output of sample.txt created on a Linux system

00000000  6c69 6e65 310a 6c69 6e65 320a           line1.line2.

Output of sample.txt create on a Windows system

00000000  6c69 6e65 310d 0a6c 696e 6532 0d0a      line1..line2..

To convert between the types of line-endings try dos2unix or fromtodos.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .