• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Dev Tips / Writing Posts with CLI Commands

Writing Posts with CLI Commands

Last updated on March 1, 2021 by Sal Ferrarello

A lot of the posts I write include command-line interface (CLI) commands to type in. I’ve found over time there are things I can do to improve how these commands are communicated.

HTML Markup

When writing a command inline, wrapping it in <code></code> tags works well (e.g. ls).

When you want to display it as a block, wrapping it in <pre><code></code></pre> works well, e.g.

ls

The CLI Prompt

There are varying opinions on whether or not your examples should include your command prompt.

When to Include the Prompt?

My recommendation is to omit the command prompt in almost all cases. It is easier to copy the command when the prompt is not included (both manually and if you have a copy button associated with your block).

Style Yes No
Inline ls $ ls
Block
ls
$ ls
Block w/ Output
$ ls
file1
file2
ls
file1
file2

The only time I recommend including the prompt is when the block includes both the typed command and the output because in this case the prompt differentiates the command to be typed and the expected output.

Which Prompt?

In the rare occasions when you do include the prompt I recommend using $ (the default prompt in bash shell).

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Presentation, Recommendations Tagged With: blogging, command line, website

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in