Carriage Returns in files after copying

Stephen L Arnold sarnold at
Sat Jul 17 23:16:19 GMT 1999

On 18 Jul 99, mludwig at had questions about Carriage 
Returns in files after copying:  

> I've got a set of shares set up on a SUN Enterprise 5500 using Samba
> 2.0.4. In Windows NT, I map a drive to the share.  When I copy a text file
> from Windows NT to the SUN, editing the file in UNIX shows that ^M has
> been added to the end of each line.  It's almost like the copy cannot
> distinguish between a text file and a binary, because the same problem
> occurs when I ftp a text file from one machine to another in binary mode.
> Any thoughts, ideas, suggestions?

The ^Ms (CR, carriage return, whatever) are not being "added" by 
samba, they're supposed to be there under Dos/windoze (DOS/win text 
files use both a CR and a LF to terminate each line).  UNIX text 
files, OTOH, only use linefeeds.  The ftp modes (binary and ascii) 
are meant to either do the CR/LF <-> LF conversion (ascii mode) or 
do nothing (binary mode).  However, ftp does not try and detect 
(based on the file) which mode to use, it just has a default 
setting.  The samba guys have chosen to make samba use binary mode 
all the time, as there is really  no reliable way to determine 
which files should be converted and which should not, without a 
human in the loop.

If you edit unix text files (eg, source code) via samba on win 
machines, then use a smart editor.  Even free ones like PFE will 
detect the file type and let you convert back and forth.

If you need to batch convert a bunch of text files, then there are 
plenty of linux/unix/win utils like AWK and perl that can do the 
job just fine.  You may also find something like DOS2unix on your 
linux system.  There was a drag'n'drop windoze util in the samba 
docs (called cr/lf_convert or something) but I couldn't get it to 
work.  Maybe you'll have better luck.


Steve Arnold  CLE (Certifiable Linux Evangelist)

More information about the samba mailing list