Cheat sheets are popular with people learning Linux. Even well-versed Linux admins like to keep certain cheat sheets handy (vi... am I right?). But, the best cheat sheet is the one you have with you... Sorry, that's an old photographers quote about cameras. However, I think it translates well.

In this Linux quick tip we will showcase a couple different utilities that give you a cheat sheet right from your command prompt. Not only will these give you a great cheat sheet for almost every command on your system; they will also allow you to edit each cheat sheet, and even create new ones. Now you can have whatever options, switches, syntax or other information that is important to you right at your fingertips. Let's get started...

Install the Command Line Cheat Sheet

Installing the "cheat sheet" is a little different on each system. Below you will find instructions to get up and running on each system.

Install Command Line Cheat Sheet on Ubuntu

Run snap to install cheat:

$ sudo snap install cheat

Now run the basic setup to configure the base cheat sheets.

$ cheat.cheatsheet-setup

Install Command Line Cheat Sheet on Fedora

Installing on Fedora is even easier since the package is available directly from DNF.

$ sudo dnf install cheat

Once installed, there is not further configuration necessary.

Install Command Line Cheat Sheet on CentOS 7 or Red Hat 7

Unfortunately cheat isn't available in the base repos like it is on Fedora. We will have to install and configure snapd to download it via snap.

First, enable the epel repo on your system. (If you are using CentOS 7 or Red Hat 8, see this link to enable epel)

sudo yum install epel-release

Install Snap:

sudo yum install snapd

Enable snapd Socket:

sudo systemctl enable --now snapd.socket

Enable classic snap support (optional):

sudo ln -s /var/lib/snapd/snap /snap

Now you have to log out and back in again. If you are ssh'd to the system simply closing your session and logging back in will do. Once logged back in, install cheat.

sudo snap install cheat

And run the initial setup:

cheat.cheatsheet-setup

Common Issues after Installation

You may get the following error after installation if you do not have the EDITOR or VISUAL environmental variables set.

failed to load config: configure EDITOR or VISUAL see: https://help.ubuntu.com/community/EnvironmentVariables

This can be fixed by setting the EDITOR environmental variable to your editor of choice.

To set it to vim:

export EDITOR=vim

To set it to nano:

export EDITOR=nano

To make this setting permanent you will have to add it to your .bashrc or .profile files. I added the following to my ~/.profile file on my Ubuntu box:

EDITOR=vim export EDITOR

Using the Command Line Cheat Sheet

Now that you have cheat installed, you can simply call it followed by the command you want information about.

savona@ubuntudev:~$ cheat pushd # Pushes your current directory to the top of a stack while changing to the specified directory pushd <directory> # To return use popd popd

Get a List of Available Sheets

By default, a cheat sheet is created for each command. To get a list of all the cheat sheets you can use the -l (--list) option.

savona@ubuntudev:~$ cheat -l 7z /usr/share/cheat/7z ab /usr/share/cheat/ab alias /usr/share/cheat/alias ansi /usr/share/cheat/ansi apk /usr/share/cheat/apk apparmor /usr/share/cheat/apparmor ...OUTPUT TRUNCATED...

NOTE: Cheat sheets that are installed by default are located in /usr/share/cheat , any user specific sheets are stored in ~/.cheat/ .

Editing Sheets for Personalized Results

This is where the cheat utility really shines. Using the -e (--edit) option you can edit or even create a cheat sheet. Using the edit option basically opens the text file in your favorite editor. Once the file is open you can edit it as you see fit. You can add your favorite options, or even just notes you would like to remember.

Creating a Custom Sheet

To create a custom cheat sheet you can use the -e (--edit) option followed by the name of the cheat sheet that does not yet exist. For example, let's say you wanted to create a cheat sheet for a script you wrote called putorius.sh. Simply call cheat -e putorius.sh like so:

savona@ubuntudev:~$ cheat -e putorius.sh savona@ubuntudev:~$ savona@ubuntudev:~$ savona@ubuntudev:~$ cheat putorius.sh #This is a script that does stuff putorius.sh -w savona@ubuntudev:~$

No Installation Cheat Sheet via Curl

This is a cool little utility that allows you to pull a cheat sheet for any (well almost any) command. Simple use curl to call the URL followed by the command and you will get a little cheat sheet of it's options.

I cannot promise that it has every command available. However, I tried for a couple minutes to stump it and I was unable to find an unavailable command.

This can be very useful, especially if you are unable to install packages. For additional convenience you create an alias a function to call it quickly and easily. I added the following function to my bashrc file.

function ct { curl cheat.sh\/"$1"; }

Now, whenever I need to see the cheat sheet for a command I can use ct followed by the command.

[savona@putor ~]$ ct ls # ls # List directory contents. # List files one per line: ls -1 # List all files, including hidden files: ls -a ...OUTPUT TRUNCATED...

Conclusion

Anyone familiar with me will tell you that I like to stay on the command line. I can see these Linux cheat sheets being great for people new to Linux. I wish I would have had this 20 years ago. There is also value in the cheat sheets for experienced admins. Even though I am pretty set in my ways, I still need to look up options every once in a while.

If you love to stay command line bound then you might enjoy some of the links below!

Resources and Links