Skip to main content

Drop man pages for this Linux command

The Linux cheat command lets you look up common command-line flags and arguments quickly without leaving the CLI.
Image
Linux terminal

Photo by Markus Spiske on Unsplash

Every sysadmin has a magical combination of command-line flags and arguments in their toolbox to accomplish a specific task. However, these esoteric command-line combinations are often very difficult to remember. Frequently, this results in a notes.txt file lying somewhere on a workstation, collecting dust, that's never quite available when you need it.

The cheat utility allows you to organize your command-line knowledge into cheat sheets that you can access easily without leaving the command-line interface (CLI). The cheat command is like the command-line version of the crib sheets you may have used in school. This article walks through the installation, configuration, and basic usage of cheat.

[ Keep your most commonly used commands handy with the Linux commands cheat sheet. ]

Install cheat

The cheat tool ships as a single binary without any runtime dependencies, so installation is very easy. While cheat works on multiple platforms, this article focuses on the Linux version. Installation simply requires downloading and extracting the binary to an appropriate location on your PATH.

First, download and unzip the cheat binary:

$ wget https://github.com/cheat/cheat/releases/download/4.3.1/cheat-linux-amd64.gz
$ gunzip cheat-linux-amd64.gz

Next, make cheat executable and place it on your PATH:

$ chmod +x cheat-linux-amd64
$ sudo mv cheat-linux-amd64 /usr/local/bin/cheat

Finally, confirm that cheat works:

$ cheat -v
4.3.1

The first time you run cheat, it prompts you to create an initial configuration file and download the amazing collection of community cheat sheets.

[ Learn how to manage your Linux environment for success. ]

Configure cheat

The default cheat configuration is suitable for getting started, but there are a few settings that I always tweak when I install cheat on a new system. You can locate the YAML configuration file by using the --conf flag:

$ cheat --conf
/home/acritelli/.config/cheat/conf.yml

You can then edit the file using your preferred text editor. The configuration is straightforward, but there are two settings that I usually adjust. The first is the editor used to edit cheat sheets with the cheat -e command. The default /usr/bin/editor is fine for terminal-based systems, but I always set this to my preferred graphical editor when using cheat on my laptop or workstation.

I use Visual Studio Code, so I set this accordingly:

editor: /usr/bin/code

You can also configure cheat to paginate longer output with the page directive. I set this to the recommended value for Linux, which uses less to paginate output:

pager: less -FRX

The cheat command searches for cheat sheets in a list of configured locations. The cheatpaths directive specifies an ordered list of locations where cheat will look for a given cheat sheet. I almost always leave this at the default value, but you can add any additional cheat paths to this list as needed. See the official documentation for more information.

cheatpaths:
  - name: community
    path: /home/acritelli/.config/cheat/cheatsheets/community
    tags: [ community ]
    readonly: true
  - name: personal
    path: /home/acritelli/.config/cheat/cheatsheets/personal
    tags: [ personal ]
    readonly: false

Explore and edit existing cheat sheets

The best way to get started with cheat is to explore the dozens of available community cheat sheets. You can view all of the cheat sheets on a system by using the cheat -l command:

$ cheat -l
title:                    file:                                                                         tags:
7z                        /home/acritelli/.config/cheat/cheatsheets/community/7z                        community,compression
ab                        /home/acritelli/.config/cheat/cheatsheets/community/ab                        community
acl                       /home/acritelli/.config/cheat/cheatsheets/community/acl                       community
ag                        /home/acritelli/.config/cheat/cheatsheets/community/ag                        community
...

To view a cheat sheet, simply enter cheat {cheatsheet_name}. For example, to look at the cheat sheet for the lsblk command, type:

$ cheat lsblk
# To show all available block devices along with their partitioning schemes:
lsblk

# To show SCSI devices:
lsblk --scsi

# To show a specific device:
lsblk /dev/sda

# To verify TRIM support:
# Check the values of DISC-GRAN (discard granularity) and DISC-MAX (discard max bytes) columns.
# Non-zero values indicate TRIM support
lsblk --discard

# To fetch info about filesystems:
lsblk --fs

# For JSON, LIST or TREE output formats use the following flags:
lsblk --json
lsblk --list
lsblk --tree # default view

The community cheat sheets contain hundreds of useful tips for dozens of common commands. However, sometimes you will want to add your own tips to these cheat sheets. You can edit an existing cheat sheet using the -e flag. The cheatpath for community cheat sheets is set to read-only by default, so any changes are made to copies in your local cheat sheet directory.

[ Download a Bash shell scripting cheat sheet. ]

For example, I can add information about how to view block device serial numbers to the lsblk cheat sheet:

Create a new cheat sheet

The community examples cover a wide variety of tools you will likely encounter in your daily activities as a sysadmin. However, you will undoubtedly come across your own commands that you want to add to cheat. You can create a new cheat sheet with the -c flag.

I have recently worked with the open source Conftest tool to test configuration using Open Policy Agent policies. I often forget the exact flags and subcommands that I use infrequently, so I created my own cheat sheet:

Cheat sheets don't have to correspond to a command directly. You can create a cheat sheet for anything you want to look up at the CLI quickly.

Organize with cheat

This article provides a basic introduction to the cheat command on Linux. You learned how to install, configure, and use cheat to look up common command-line flags and arguments quickly. cheat also has many advanced features, such as searching and tagging. These features can help you organize and search your cheat sheets, and I recommend you review the README for more information about the capabilities of cheat.

Topics:   Command line utilities   Linux  
Author’s photo

Anthony Critelli

Anthony Critelli is a Linux systems engineer with interests in automation, containerization, tracing, and performance. He started his professional career as a network engineer and eventually made the switch to the Linux systems side of IT. He holds a B.S. and an M.S. More about me

Try Red Hat Enterprise Linux

Download it at no charge from the Red Hat Developer program.