# What does CR, carriage return means?

**URL:** <https://forum.freecodecamp.org/t/what-does-cr-carriage-return-means/144231>\
**Category:** General\
**Created:** [August 28, 2017, 5:07am UTC](https://forum.freecodecamp.org/t/what-does-cr-carriage-return-means/144231 "2017-08-28T05:07:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![easterrc](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@easterrc](https://forum.freecodecamp.org/u/easterrc)\
**Post date:** [August 28, 2017, 5:07am UTC](https://forum.freecodecamp.org/t/what-does-cr-carriage-return-means/144231/1 "2017-08-28T05:07:04Z")

</div>

I’ve looked it up on google and every time I see this:

**’carriage return means moving the cursor to the beginning of the line.'**

That doesn’t explain anything to me. And when they introduce the concept of typewriter and computer, it makes it even more confusing because i’ve never typed on a typewriter before so i cant picture it in my head. but obviously i use a computer all the time so i think \r is like hitting the ‘enter’ keyboard button, and the blinking ‘l’ going to a new line.

Is that what it means?

---

<div class="post-metadata">

**Author:** ![TheGallery](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/thegallery/32/161197_2.png) [@TheGallery](https://forum.freecodecamp.org/u/TheGallery)\
**Post date:** [August 28, 2017, 7:19am UTC](https://forum.freecodecamp.org/t/what-does-cr-carriage-return-means/144231/2 "2017-08-28T07:19:53Z")

</div>

It’s \n that works like pressing `Enter` . I am not really an expert in these things, but the [first and second answers here](https://stackoverflow.com/questions/12747722/what-is-the-difference-between-a-line-feed-and-a-carriage-return), explain it pretty well.

---

<div class="post-metadata">

**Author:** ![easterrc](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@easterrc](https://forum.freecodecamp.org/u/easterrc)\
**Post date:** [August 29, 2017, 1:52pm UTC](https://forum.freecodecamp.org/t/what-does-cr-carriage-return-means/144231/3 "2017-08-29T13:52:04Z")

</div>

i created an image to illustrate my qns and the black rec bars are the blinking cursors.

 ![r](https://global.discourse-cdn.com/freecodecamp/original/3X/d/1/d172f6d6ed570e41f49a418dfadabde5489daf91.jpg)

---

<div class="post-metadata">

**Author:** ![ppc](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ppc/32/63349_2.png) [@ppc](https://forum.freecodecamp.org/u/ppc)\
**Post date:** [August 29, 2017, 7:38pm UTC](https://forum.freecodecamp.org/t/what-does-cr-carriage-return-means/144231/4 "2017-08-29T19:38:04Z")

</div>

the difference between newline “\n” ascii 0x0a and carriage return “\r” ascii 0x0d is difficult to see in a web page

if you have a console terminal e.g. windows powershell or linux bash you can try the following oneliners - use ctrl-c to kill either command

```auto
# windows powershell command
# newline is `n - carriage return is `r
for($i=0;;++$i) { $line=if($i%2) {"`rcr $i"} else {"`nnl $i"} write-host -nonewline "$line"; sleep 5 }

```

```bash
# linux bash command
# newline is \n - carriage return is \r
for((i=0;;++i)); do ((i%2)) && line="\rcr $i" || line="\nnl $i"; echo -en "$line"; sleep 5; done

```

The output of either command is like this - every even numbered line starts with a newline 0x0a - every odd numbered line starts with a carriage return 0x0d

the first line appears

```auto
nl 0

```

then 5 seconds later - the line is overwritten because the carriage return begins new output at the beginning of the current line

```auto
cr 1

```

then 5 seconds later - a new second line appears

```auto
cr 1
nl 2

```

then 5 seconds later - the second line is overwritten due to the carriage return

```auto
cr 1
cr 3

```

so every “nl” line shows up for 5 seconds before being replaced with a “cr” line

---

<div class="post-metadata">

**Author:** ![easterrc](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@easterrc](https://forum.freecodecamp.org/u/easterrc)\
**Post date:** [August 31, 2017, 6:17am UTC](https://forum.freecodecamp.org/t/what-does-cr-carriage-return-means/144231/5 "2017-08-31T06:17:34Z")

</div>

hmmm okayyy. but i use mac

thanks for ur effort and reply though. appreciate it!

---

<div class="post-metadata">

**Author:** ![ppc](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ppc/32/63349_2.png) [@ppc](https://forum.freecodecamp.org/u/ppc)\
**Post date:** [August 31, 2017, 7:39am UTC](https://forum.freecodecamp.org/t/what-does-cr-carriage-return-means/144231/6 "2017-08-31T07:39:26Z")

</div>

the bash command should work on mac too

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:59pm UTC](https://forum.freecodecamp.org/t/what-does-cr-carriage-return-means/144231/7 "2021-01-16T17:59:59Z")

</div>


