User Tools

Site Tools


guides:software:files

This is an old revision of the document!


Files in Windows and Linux

There is a difference in how files are stored on these two operating systems.

By default, when files are created on a windows system, the end of the file is marked with a ctrl-r and a ctrl-n. The user does not insert this, it is done automatically by the software. This is not the case in the linux/unix environment. The end of line in linux is marked only by the ctrl-n. When performing text processing, the ctrl-r will cause problems in the linux environment.

Checking for **CTRL-R** on Linux

To see if your file contains ctrl-r use the linux command od. Od stands for Octal Dump and will display the contents of the file in various formats. In this case, you should run od -c filename. This will display each character in the file, with some special characters, like ctrl-r and ctrl-n proceeded by a slash.

In this example, the file foo.cpp has been created on a computer running windows and transferred to a computer running linux. To check the format, the user runs od -c foo.cpp. Note that each line ends in \r and \n

 
$ more foo.cpp
#include <iostream>

using namespace std;

int main() {
   cout << "Hello World " << endl;

   return 0;
}

$ od -c foo.cpp
0000000   #   i   n   c   l   u   d   e       <   i   o   s   t   r   e
0000020   a   m   >  \r  \n  \r  \n   u   s   i   n   g       n   a   m
0000040   e   s   p   a   c   e       s   t   d   ;  \r  \n  \r  \n   i
0000060   n   t       m   a   i   n   (   )       {  \r  \n            
0000100   c   o   u   t       <   <       "   H   e   l   l   o       W
0000120   o   r   l   d       "       <   <       e   n   d   l   ;  \r
0000140  \n  \r  \n               r   e   t   u   r   n       0   ;  \r
0000160  \n   }  \r  \n
0000164

In the following example, the file bar.cpp was produced on a system that did not add ctrl-r to the end of each line.

$ more bar.cpp
#include <iostream>

using namespace std;

int main() {
   cout << "Hello World " << endl;

   return 0;
}
$ od -c bar.cpp
0000000   #   i   n   c   l   u   d   e       <   i   o   s   t   r   e
0000020   a   m   >  \n  \n   u   s   i   n   g       n   a   m   e   s
0000040   p   a   c   e       s   t   d   ;  \n  \n   i   n   t       m
0000060   a   i   n   (   )       {  \n               c   o   u   t    
0000100   <   <       "   H   e   l   l   o       W   o   r   l   d    
0000120   "       <   <       e   n   d   l   ;  \n  \n               r
0000140   e   t   u   r   n       0   ;  \n   }  \n
0000153

Note in this example that lines end with a newline (\n).

guides/software/files.1609773035.txt.gz · Last modified: 2022/08/02 11:59 (external edit)