I want to know what the best way to write and highlight a command is.

Many people (with a lot of reputation) write commands like this:

$ sudo apt-get update

If someone copies this command as it is, it won't work (and I think many people do that, because I remember I did at one point)

Some people write it like this sudo apt-get update I think this is used when there is just a single command and it's written within a statement, like I just did.

I choose to write it like most people

sudo apt-get update

I consider this is the most logical way to go about it

My questions are

  • Should I edit out $ signs?
  • Does $ sign mean something more than what my ground assumptions are?
  • Or simply, what is the correct way to do it?

this question was inspired by thought of editing this answer

  • 1
    I actively edit it out unless, like terdon says, it's to distinguish between the command and the output :P
    – Zanna Mod
    Commented Apr 24, 2017 at 14:21
  • 1
    we even have a question showing why this is a real problem!
    – Zanna Mod
    Commented Apr 24, 2017 at 14:28
  • 1
    @Zanna that is really out there, I sent a link of a question to my friend he came up with the same problem Commented Apr 24, 2017 at 14:32

2 Answers 2


The rule of thumb is: if you are only showing the command, don't show the prompt ($). If you are showing the command and its output, use the prompt to distinguish between them. For example:

To foo the bar, run:

foo bar    


This should do what you want:

$ foo bar
output line 1
output line 2

In other words, use the $ when it makes things clearer, don't use it when it can be confusing. If you want to show both the command and its output, it is very hard not to be confusing without the $ so it is better to have it. Conversely, when you just want to show a command, the $ doesn't help or make it clearer, so leave it out.


I prefer this type of style:

sudo do-whatever

Really, the only purpose of putting $ in there is to signify that you're running the command as you instead of root. (#)

  • so basically you shouldn't use it ($) with sudo? Commented Apr 24, 2017 at 14:17
  • 1
    @SumeetDeshmukh - Uh not exactly... see, you are still running the sudo command from your user... you would put # to signify that the command needs to be run as root, like # apt-get update Commented Apr 24, 2017 at 14:19

Not the answer you're looking for? Browse other questions tagged .