How to access Linux command cheat sheets from the command line

The power of Linux command line is its flexibility and versatility. Each Linux command comes with its share of command line options and parameters. Mix and match them, and even chain different commands with pipes and redirects. You get yourself literally hundreds of use cases even with a few basic commands, and it's hard even for seasoned system admins to get used to them all. That's when command line cheat sheets come to our rescue.

I know man pages are still our best friend, but we want to be efficient and strategic by having quick reference cards at our disposal. Your ultimate cheet sheets could be hanging on your office wall with pride, or secretly stored in your hard drive as PDF files, or even be the background image on your desktop.

Alternatively, use yet(!) another command to access your favorite command line cheat sheets. That is, use cheat. Which is a command line tool allowing you to access, create or update cheat sheets from the command line. The concept is really simple, yet cheat turns out to be quite useful. This tutorial is about how to use cheat command on Linux. You don't need a cheat sheet for using cheat command. It's that simple.

Installing Cheat on Linux

First install Git if you haven't:

$ sudo apt-get install git (Debian-based system)
$ sudo yum install git (RedHat-based system)

Also install Python package installer pip.

Finally, install cheat using the following commands.

$ sudo pip install docopt pygments
$ git clone https://github.com/chrisallenlane/cheat.git
$ cd cheat
$ sudo python setup.py install

Configuring Cheat

There is not much to configure for cheat command.

One thing to recommend is to enable command-line autocompletion. That way, when you look up a cheat sheet, you can use [TAB] key to auto-complete the name of the command you want to check. Here is how to enable autocompletion for bash.

$ wget https://github.com/chrisallenlane/cheat/raw/master/cheat/autocompletion/cheat.bash
$ sudo cp cheat.bash /etc/bash_completion.d/

They provide autocompletion scripts for other shells such as zsh and fish as well.

Another thing is to define an EDITOR environment variable. This variable should point to a text editor that you want to use when creating or updating a cheat sheet. For example, if you want to use Vim editor, put the following in ~/.bashrc.

export EDITOR=/usr/bin/vim

Log out and log back in to activate autocompletion and updated .bashrc.

Basic Usage of Cheat

One cool thing about the cheat command is that it comes with pre-built cheat sheets for more than 90 popular Linux commands. To get a list of available cheat sheets:

$ cheat -l

To access a cheat sheet of a specific command, simply run cheat with the name of the command:

$ cheat <command-name>

You can search all the cheat sheets that contain a specific keyword by using "-s" option:

$ cheat -s <keyword>

In many cases, cheat sheets that are useful to some folks may not that helpful to others. To personalize pre-built cheat sheets, cheat command allows you to create a new cheat sheet or update existing ones. To do so, cheat command can keep local copies of cheat sheets in ~/.cheat directory.

To take advantage of cheat's editing feature, first make sure that the EDITOR environment variable is set to the full path of your default text editor. Then copy (non-editable) built-in cheat sheets to ~/.cheat directory. You can find where the built-in cheat sheets are by running the following command. Once you know where they are, simply copy them over to ~/.cheat directory.

$ cheat -d
/usr/lib/python2.6/site-packages/cheat/cheatsheets
$ cp /usr/lib/python2.6/site-packages/cheat/cheatsheets/* ~/.cheat

Now you can create or update a cheat sheet by using "-e" option:

$ cheat -e openssl

As you can imagine, the cheat's editing feature is very useful to tailor a local cheat sheet repository to meet your needs. If you believe in sharing knowledge, you are more than welcome to contribute your cheat sheets to the cheat command's official Git repository, so everyone can benefit from them.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

7 thoughts on “How to access Linux command cheat sheets from the command line

Leave a comment

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

Current ye@r *