File format changed to DOS after copying between Linux boxes?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
File format changed to DOS after copying between Linux boxes?
In short: I copy a text-file in Linux format from opensuse1 to opensuse2.
The file format is changed to DOS!
Details:
I have 2 servers running OpenSuse 12.2, one for testing one production.
I only use Linux myself on all my computers. (Home: LMDE, laptop: Mint14 - both with Mate desktop.)
What I do is write a few bash scripts on suse-test, try them out and then transfer them to suse-prod.
I have transferred the files different ways - sometimes using scp, or sometimes with copy-paste by mouse-copying (mark+middle-click) from nano on terminal suse-test to nano on terminal suse-prod. Also sometimes I open the test-file with Kate on my laptop using fish://, then I copy (middle-click) in nano (as root) on terminal suse-prod or save to my homedir on suse-prod directly with Kate.
All of these ways normally works fine, about a dozen files transferred this way.
But the file I transferred yesterday ended up on suse-prod in DOS format!
Problem in itself is fixed, no problem converting to Unix format, but I'm so curious about how / why this happened?
Yes - well, it's the different linebreaks that causes problems although it is not what I checked.
Symptom: When executing the file I got error
Code:
bash: /home/peterh/dl_trans/sbin/dl_control: /bin/bash^M: bad interpreter: No such file or directory
The character I put in bold is what shows it's wrong kind.
I then opened the file with nano, got a message "converted from DOS format".
I did not get that message when opening original file.
My solution was simply to save again in nano, and remove the "DOS Format".
Text editors usually have an option to save files using Unix vs DOS formated newlines (ie linebreaks) so it could have happened like that. Do you remember how you transfered the file?
Not sure, I opened it with kate in my computer using fish://
Then I either chose "save as" in Kate, or copied and pasted in nano on suse-prod.
Kate does not have an option (that I can see) to save in other format, I have used all these methods earlier without any problem.
I have recently updated my laptops system though, wonder if something has changed - mainly thinking about the fish-protocol, will test later when I have more time.
Very crazy this...
Checking what I did, I'm pretty sure I saved it in Kate directly to my homedir on suse-prod.
When I got that error message, I scp'd directly from suse-test to suse-prod.
On suse-test the file executed fine, no "DOS format" message in nano. On suse-prod it didn't execute because of the linebreaking, message "DOS format" in nano. HOWEVER! Doing the same with other bash-files this does not happen! They execute fine & re NOT in DOS format!
In Kate you have it in menu "Tools"/"End of line" for current document. Check also "Settings"/"Open/Save" on "General" tab for deafult setting and on "Modes&Filetypes" tab where are individual settings based on type of file you are opening.
Can you write what is filename with extension of this file?
In Kate you have it in menu "Tools"/"End of line" for current document. Check also "Settings"/"Open/Save" on "General" tab for deafult setting and on "Modes&Filetypes" tab where are individual settings based on type of file you are opening.
I have never ever touched those settings!
File on suse-test has correct line endings.
Default setting for EOL is "DOS/Windows", but "Automatic eol detection" is marked.
And, as I mentioned, this has never happened before - and it did happen when copying via scp!
Now I can't recreate it???
The file has no extension, I don't use that for bash scripts.
If you had "DOS/Windows" as default setting, then you probably did copy (from Unix EOL) and paste to newly created by kate file which did conversion to satisfy your default Windows EOL. The "Automatic detection" is only used for opening files, to set line ending properly in case you want to append some new lines. But by "scp", I think its impossible, especially you can't recreate it.
You have a good thought there, and very good to know that Kate's "Automatic detection" is only used for opening files not creating, but still no go.
You see, I never created a new file & pasted to it, I just saved it to a new location. While you might think this is actually the same as creating a new file, it doesn't happen with any other file. They always keep the original linebreak setting.
And what's more, I've done this many many times before, never had this problem.
Plus! It did happen when I scp'd too!
This is all crazy, I have tried so many ways now but I simply can't recreate the error.
Well, of course that's good in one way, I just wander what the h*ck went wrong this morning. (And before you ask: YES I had had my coffee I WAS awake! )
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.