You can use \r to move the "cursor" to the beginning of the line. Note that neither \b nor \r deletes the printed characters. It just moves the "cursor" back one character and to the beginning of the line, respectively.
echo -e 'foooo\b\b\b\b\bbar'
echo -e 'foooo\rbar'
If you want the characters deleted then you have to use the following workaround:
echo -e 'fooooo\r \rbar'
Excerpt from man echo:
If-e is in effect, the following sequences are recognized:
\0NNN the character whose ASCII code is NNN (octal)
\a alert (BEL)
\c produce no further output
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
NOTE: your shell may have its own version of echo, which usually super‐
sedes the version described here.Please refer to your shell's docu‐
mentation for details about the options it supports.
If you want to write something else, on the line you're erasing, add a -n flag on the echo above, or else you'll go to a new line right after deleting it. Also, append a \r to the string above, or your new content won't go to the beginning of that line.
– djjeckNov 20 '14 at 1:46
This will write xyzzyxyzzy, then return to the beginning of the line and send the "clear to end of line" sequence to the terminal, then write foobar. The -n makes echo not add a newline after the foobar.