Chapter 6. Getting Stuff Done

Screen Output


Print simple text on standard output.


Print formatted text on standard output.


Print repeated text on standard output.


Print a sequence of numbers on standard output.


Clear the screen or window.

Linux provides several commands to print messages on standard output. Each has different strengths and intended purposes. These commands are invaluable for learning about Linux, debugging, writing shell scripts (see “Programming with Shell Scripts”), or just talking to yourself.




- file

-- opt



echo [options] strings

The echo command simply prints its arguments:

echo We are having fun
We are having fun

Confusingly, there are several different echo commands with slightly different behavior. There’s /bin/echo, but Linux shells typically override this with a built-in command called echo. To find out which you’re using, run the following command:

type echo
echo is a shell builtin

Useful options


Don’t print a final newline character.


Recognize and interpret escape characters. For example, try echo 'hello\a' and echo -e 'hello\a'. The first prints literally and the second produces a beep.


Don’t interpret escape characters: the opposite of -e.

Available escape characters are:


Alert (play a beep)




Don’t print the final newline (same effect as -n)


Form feed


Line feed (newline)


Carriage return


Horizontal ...

Get Linux Pocket Guide, 4th Edition, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.