There are likely as many ways of doing this as there are DocBook authors; however, here are two ways that you might find useful. Thanks to Y Giridhar Appaji Nag and Martin Brown for the markup used here.
Example D-1. Command Prompt with programlisting
<programlisting> <prompt># </prompt><userinput><command>cd</command> /some/dir</userinput> <prompt># </prompt><userinput><command>ls</command> -l</userinput> </programlisting>
# cd /some/dir # ls -l
Example D-2. Command Prompt with screen
First create a general entity in the internal subset at the very beginning of your document. This entity will define a name for the shortcut which you can use to display the full prompt at any point in your document. <!ENTITY prompt "<prompt>[user@machine ~/dir]$</prompt>">
For more information about entities, read Section D.8.
<screen> &prompt; <userinput>cd /some/dir</userinput> &prompt; <userinput>ls -l</userinput> </screen>
[user@machine ~/dir]$ cd /some/dir [user@machine ~/dir]$ ls -l
If you would like to add the output of your commands you can add <computeroutput> text</computeroutput> within the <screen> or <programlisting> as appropriate.