Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Patrick Jan 1 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 at 15:57
add comment

5 Answers

up vote 4 down vote accepted

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

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

or

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

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

share|improve this answer
    
+1 For making me eat my words vis, there are no ANSI sequences involving vertical movement. –  TAFKA 'goldilocks' Jan 1 at 21:24
add comment

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.

share|improve this answer
    
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 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. –  TAFKA 'goldilocks' Jan 1 at 17:38
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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

But moving the cursor a line up does not work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.