YTread Logo
YTread Logo

What's a Carriage and Who's Feeding it Lines? CRLF - Computer Stuff They Didn't Teach You #1

May 31, 2021
Hello friends, I'm Scott Hanselman. I wanted to try this. This is the beginning. I hope this is the first of many video series about all the things

they

didn

't

teach

you in school when you decided to become a programmer or engineer. or developer or some kind of techie, I think there's a dearth of

computer

science history and sometimes I just sit there and

they

're like, hey, let's learn in a program and there's all these weird little things that I don't tell you. . I thought I'd make a bunch of little videos, this is a test. If you like it, let me know in the comments

what

other topics you'd like me to cover, so

what

I want to talk to you about is the

carriage

return line change.
what s a carriage and who s feeding it lines crlf   computer stuff they didn t teach you 1
What is a car? Who feeds him

lines

? Where he came from? Why should I care? How does that relate to text files and git and Windows and Linux and Mac? So this is what I'll tell you, so I'm on a Windows machine right here and I'm sitting at my desk. I happen to be using the Windows terminal. Your terminal might look like this and that's fine. What I did was go to the Start menu, press the Windows key and run. I typed CMD, okay, and if I go out here and save it to a CD on my desktop and say, copy the text from pecan's test point, you can try this.
what s a carriage and who s feeding it lines crlf   computer stuff they didn t teach you 1

More Interesting Facts About,

what s a carriage and who s feeding it lines crlf computer stuff they didn t teach you 1...

In fact, I am copying from the console to a file, this is the same as when you copy file 1 to the file to accept the first file that I am copying from as the console, which is the screen here, I am actually copying from the keyboard to the file dot txt when I type ABC enter and then I press control Z and I will say a copy of a file just like you copied it yourself and all of them will then type file dot txt and I will say notepad file dot txt and I will press enter and the notepad will appear notes and if you are on a recent version of Windows 10 in In the bottom right corner here it will say Windows

crlf

What is it?
what s a carriage and who s feeding it lines crlf   computer stuff they didn t teach you 1
Well

crlf

, for many of you you will realize that it means

carriage

return line feed, so what is a line advancing carriage? What is the problem? Well, the idea is on a typewriter or a

computer

. or mainframe computer that talked to a typewriter or talked to some type of printer, there was a cart that you had on the side, the cart is what carries the paper and you would get to the end of a line and you would push the cart to return it, you would press this carriage return, it would go back and forth to the other side and then you would turn this knob which would then feed the line so that the carriage return line feed are control characters that appear. in a text file for programming or to insist to the printer that it should return the carriage and then feed the line this is where things get interesting in Windows text files, even today in 2020 they have a carriage return and a line feed after each line on a Linux machine they only have a line feed after each line and on a Mac they only have a carriage return on each line, so why should you care?
what s a carriage and who s feeding it lines crlf   computer stuff they didn t teach you 1
Things get a little interesting when you start moving files between systems, so here I am. and I can't see what you see, I can't see that it's a crlf there's no there's no Enter key there's no X or a big number or something that says yes there's an enter there so how can we visualize that? As we can? look well i have an application on my machine called hex dump, you can go to google to see hex dump, if you have linux you already have this file, if you have windows you can download it in hex dump for windows. and I'm just going to say hex dump file dot txt and I see 61 62 63 which are the ASCII codes for ABC I see 0d 0a 0d is 13 and 0 a is 10 how do I know 0 is 10 1 because it's in hexadecimal? 1 2 3 4 5 6 7 8 9 ABCDE F and a is hexadecimal for 10, so 0 is CR and zero a is ten or LF.
I can go through and look at an old ASCII code chart. ASCII is the American standard code for information interchange. an old thing that's still with us today and you can see right there, the carriage return is 13 and the line feed is 10 and if I go up and look at ABC, that's 61 62 and 63 63 The carriage return ABC, forward of line, that's what I got when I made that file now this is where things get interesting What if I got something from github? Maybe I'm a programmer, for example. I'll go and grab this github readme file comm /s Hanselman crlf examples.
I'm going to take the URL so I'm just going to copy it and paste it to the clipboard, there I'll go out and say git clone and I'll paste it and I'll clone it okay and I go into that folder and there's my readme file. and I can go and look at that file and there it is, it has a couple of

lines

, we can do the hex dump trick and we can see we have an example of crlf, carriage return, line feed, carriage return, line feed, it looks like there's one here and one there, there's a line, then there's line space too and then a trailing carriage return line feed, that's interesting, but if we move on to an advantage, which is a different operating system here, I'm using the Windows Subsystem for Linux on my machine, but you could use any open Jim machine you have lying around and I say git clone and I do the exact same thing when I get the same file, okay, there it is, I'll look at it and say hex dump and see the example of little Sarah's life line feed line space one line feed line space two line feed what's going on there well text files on Linux only line feed if I were on a Mac it would be a carriage return, so how is this happening? if I go and look at Windows and type get config -- get core dot Auto crlf so that it is set to true within Windows and it is not set in my Ubuntu world, if we take a look at what the configuration looks like. when you first install it, it says, "Hey, I'll check things Windows-style, which means it will lie to you and confirm things Unix-style, where when you send a text file, crlf will be converted to LF, so What that means is for cross-platform projects, get lies to you: it puts text files on your Windows machine and keeps them on disk with carriage returns and line feeds, but the reality is that when you save them to git and store them in line, it's everywhere in the world except your Windows machine which is a line feed now if you wanted to go and use a more sophisticated editor, for example, you wanted to go and say code dot and then use Visual Studio code to open that folder I can open the readme file dot text and I can see in the bottom corner here the option for crlf or LF and of course you'll notice that the file doesn't look any different if I go and press LF, press save, come back here and say hex.dump suddenly now that we're in LF most code editors are smart at that

stuff

, the new notepad and windows 10 are smart at that Visual Studio is smart at that Visual Studio code is smart at that , so our great national nightmare is almost over, but you should be You need to be careful if you open something in an old text editor and things look weird and they're all on one line and you don't know what's going on.
Be sure to check line endings. Make sure you are aware of it. what your get settings are set to and make sure you don't open something in a code editor that isn't aligned to the ending and then don't accidentally change all the line endings without letting it know that we're 1/5 Halfway Through the Century XXI and we are still thinking about the old Smith Coronas and the old printers with carriages and line feeds that are with us today and that for the most part we have standardized just the line feed, but now Windows Notepad and Windows is generally smart about this, but now it's something you need to think about because when you're debugging a problem confused about something going wrong with your code, you might want to think about whether you're being aware of carriage returns and forwards. line so that's kind of a thing they

didn

't

teach

you in school if you want to see more videos about what they didn't teach you in school please let me know in the comments Thanks and subscribe that's something you're supposed to say when I have YouTube and then they point here and say click the subscribe button.

If you have any copyright issue, please Contact