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 have an SMB connection to an Ubuntu Server 12.10 host that has shell scripts and config files I want to edit with a Windows 7 client using Notepad++. I am able to open the files and make changes, but as soon as I save them, with no changes to the character encoding, they become unreadable on the host.

How can I edit and save the files in Windows 7 so they can be read and executed in Ubuntu Server 12.10?

share|improve this question
    
What does 'unreadable' mean? – terdon Jan 16 '13 at 15:18
    
@terdon It means the Tomcat server using the config files stops working. – Keyslinger Jan 16 '13 at 15:25
    
OK, see Jim's answer then. Or mine. – terdon Jan 16 '13 at 15:26
up vote 4 down vote accepted

EDIT: You can enable Unix line termination in Notepad++ in Edit -> EOL Conversion -> Unix Format.

One of the most common problems with text file compatibility between Unix and Windows systems is that Windows' notion of line termination is CRLF (carriage-return + linefeed, ascii 13 and 10), while Unix uses just LF (10). This is probably getting you an error like ./foo.sh: bad interpreter: /bin/sh^M: no such file or directory.

There's a utility called dos2unix that will convert any existing files for you, on the Ubuntu side:

apt-get install dos2unix
dos2unix myscript.sh

That modifies the file in-place to strip out the CRs.

share|improve this answer

As Jim said, the problem is probably line termination. You can fix this on the Linux server by running this command on your modified files:

sed -i 'N;s/\r\n/\n/g' file
share|improve this answer
    
Jim's response helped me, but I'll keep this in mind in case I ever find myself without access to either of the solutions he gave me. – Keyslinger Jan 16 '13 at 15:40
    
Just to clarify, he gave you one solution. The first command just installs the necessary program, you will only need to run it once. – terdon Jan 16 '13 at 15:44

You must log in to answer this question.

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