Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of \r on linux systems

I'm looking at some linux specific code which is outputting the likes of:

\r\x1b[J>

to the std io.

I understand that <ESC>[J represents deleting the contents of the screen from the current line down, but what does \r do here?

I'm also seeing the following:

>user_input\n\r>

where user_input is the text entered by the user. But what is the purpose of the \r here?

like image 239
Baz Avatar asked Oct 18 '25 15:10

Baz


1 Answers

The character '\r' is carriage return. It returns the cursor to the start of the line.

It is often used in Internet protocols in conjunction with newline ('\n') to mark the end of a line (most standards specifies it as "\r\n", but some allows the wrong way around). On Windows the carriage-return newline pair is also used as end-of-line. On the old Macintosh operating system (before OSX) a single carriage-return was used instead of newline as end-of-line, while UNIX and UNIX-like systems (like Linux and OSX) uses a single newline.

like image 116
Some programmer dude Avatar answered Oct 21 '25 06:10

Some programmer dude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!