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.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIf 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.
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.
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.
man 7 urxvt
.man 7 urxvt
didn't work for me (OSX), but I'll look for the man page for the terminal.