I found that by printing \r from a script the cursor moves to the beginning of the line.

What character will move the cursor up one line?

Where is a list of these special characters?

EDIT: Working in OSX. Also, \a rings the bell.

  • You likely need to consult the man page of your terminal emulator. Most terms are xterm compatible, so if you have xterm, you can probably just use its man page. For example, on my system, I use man 7 urxvt.
    – phemmer
    Jan 1, 2014 at 15:39
  • man 7 urxvt didn't work for me (OSX), but I'll look for the man page for the terminal.
    – B Seven
    Jan 1, 2014 at 15:57

5 Answers 5


If your terminal emulator supports ANSI escape sequences, you can move the cursor up by running this:

echo -n -e '\033[2A'


ruby -e 'print "\033[2A"'

This will move the cursor up 2 lines. It works in gnome-terminal and xterm and many others.

  • +1 For making me eat my words vis, there are no ANSI sequences involving vertical movement.
    – goldilocks
    Jan 1, 2014 at 21:24

Terminal dependent positioning control can be done with tput. This includes basic high-lighting and cursor positioning. For example to move the cursor to line-10, column-1 you would use tput cup 10 1. See the tput manpages.

  • That is helpful. However, I am looking for characters and how to use an escape sequence to output from within a Ruby script, which apparently works the same way as any shell script.
    – B Seven
    Jan 1, 2014 at 15:54
  • 1
    Ruby apparently includes curses bindings, which might be worth looking into. The curses library is the most common way of creating TUI (terminal UI) apps for *nix, and includes functions for positioning the cursor on the screen.
    – goldilocks
    Jan 1, 2014 at 17:38

Those special characters are from the 7-bit ASCII set, which contains the 128 characters in this table; shell escape notation is not shown there, but \r is the 14th character (decimal value 13), CR (carriage return). The bell is the 8th character (decimal value 7). \n, known in *nix and derived realms as the newline, is the 11th character (decimal value 10), LF (line feed).

Most of the ASCII set are normal alphanumeric characters. Most of the "special characters" at the beginning of the table actually don't serve any purpose today (the newline, etc., being exceptions). ANSI compliant terminals (including most modern *nix based virtual ones) use ESC (decimal 27, octal 33) to start special control sequences (\033...) -- some of which, as Mark Plotnick points out in his answer, allow for vertical movement.

Within the table itself there is VT (decimal 11), the vertical tab, but it moves down. There are no single characters allowing for upward movement.


In addition to the previous answers, you may want to look at ncurses.

Ncurses is software for controlling writing to the console screen under Unix, Linux and other operating systems.

-- www.gnu.org


For a list of special chars, use "man echo"

But moving the cursor a line up does not work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .