Using the cheat command on Fedora Linux

The cheat command, available for installation on many Linux systems, provides an easy way to make cheat sheets available for hundreds of commands.

man looking up linux code command for user assessment by electravk getty images
electravk / Getty Images

The term "cheat sheet" has long been used to refer to listings of commands with quick explanations and examples that help people get used to running them on the Linux command line and understanding their many options.

Most Linux users have, at one time or another, relied on cheat sheets to get them started. There is, however, a tool called "cheat" that comes with a couple hundred cheat sheets and that installs quickly and easily on Fedora and likely many other Linux systems. Read on to see how the cheat command works.

First, to install cheat on Fedora, use a command like one of these:

$ sudo yum install cheat

The cheat-sheet files on Fedora will be stored in /usr/share/cheat and are all simple ASCII (text) files like this one:

$ file /usr/share/cheat/xargs
/usr/share/cheat/xargs: ASCII text

To use the cheat command, try commands like these:

$ cheat uname
$ cheat xargs
$ cheat cheat

For the uname command, the response will look like this, displaying command options and sample output:

$ cheat uname
# To print all system information:
uname -a
# Linux system-hostname 3.2.0-4-amd64 #1 SMP Debian 3.2.32-1 x86_64 GNU/Linux

# To print the hostname:
uname -n
# system-hostname

# To print the kernel release:
uname -r
# 3.2.0-4-amd64

# To print the kernel version, with more specific information:
uname -v
# #1 SMP Debian 3.2.32-1

# To print the hardware instruction set:
uname -m
# x86_64

# To print the kernel name:
uname -s
# Linux

# To print the operating system:
uname -o
# GNU/Linux

The command cheat sheets that are installed with the cheat tool include all of these:

$ cd /usr/share/cheat
$ ls
7z csplit head mutt pip snmpwalk tree
ab cups hello mv pkcon socat truncate
acl curl hg mysql pkgtools sockstat udisksctl
alias cut history mysqldump pkill sort ulimit
ansi date http nc popd split uname
apk dd hub ncat ps sport uniq
apparmor deb iconv ncdu psql sqlite3 unzip
apt df ifconfig netstat pushd sqlmap urpm
apt-cache dhclient indent nkf pwd ss vagrant
apt-get diff ip nmap python ssh vim
aptitude distcc iptables nmcli r2 ssh-add virtualenv
aria2c dnf irssi notify-send rcs ssh-copy-id wc
asciiart docker iwconfig nova readline ssh-keygen weechat
asterisk dpkg journalctl npm rename stdout wget
at du jq ntp rm strace xargs
awk emacs jrnl numfmt route su xmlto
bash export kill od rpm sudo xrandr
bower ffmpeg less openssl rpm2cpio svn xxd
bzip2 find lib org-mode rss2email systemctl yaourt
cat fkill ln p4 rsync systemd youtube-dl
cd for ls pacman sam2p tail yum
cheat gcc lsblk pass scd tar z
chmod gdb lsof paste scp tarsnap zfs
chown git lvm patch screen tcpdump zip
comm gpg man pdftk sed tee zoneadm
convert grep markdown perl shred tidy zsh
cp gs mdadm pgrep shutdown tmux
cpdf gyb mkdir php slurm top
crontab gzip more ping smbclient tr
cryptsetup hardware-info mount ping6 snap trashy

You can display a cheat sheet for any of these commands. Some will show a long series of examples and others, just a few. This, of course, depends on the command's complexity and options.

$ cheat ulimit
# Report all current limits
ulimit -a

# Unlimited file descriptors
ulimit -n unlimited

There is no man page available for the cheat command, but you can cheat on the cheat command itself to see its options:

$ cheat cheat
# To see example usage of a program:
cheat <command>

# To edit a cheatsheet
cheat -e <command>

# To list available cheatsheets
cheat -l

# To search available cheatsheets
cheat -s <command>

# To get the current `cheat' version
cheat -v

Using the cheat -l command, for example, we can see the commands, files and tags which tell where the cheat sheets came from:

$ cheat -l | head -11
title:        file:                          tags:
7z            /usr/share/cheat/7z            community,compression
ab            /usr/share/cheat/ab            community
acl           /usr/share/cheat/acl           community
alias         /usr/share/cheat/alias         community
ansi          /usr/share/cheat/ansi          community
apk           /usr/share/cheat/apk           community,packaging
apparmor      /usr/share/cheat/apparmor      community
apt           /usr/share/cheat/apt           community,packaging
apt-cache     /usr/share/cheat/apt-cache     community,packaging
apt-get       /usr/share/cheat/apt-get       community,packaging

If you want to add your own cheat sheets, you first need to select your editor and create a directory to store them.

$ export CHEAT_EDITOR=/usr/bin/vim
$ mkdir .cheat

Then use the cheat -e command to create your cheat sheet:

$ cheat -e hello

Here's the hello file which contains a sample cheat sheet for this new command:

$ cat hello
Hello, World!
=============
For some reason, the world never says hello back, but saying "Hello, World!"
is something of a Unix/Linux tradition.

Now copy the file to the /usr/share/cheat directory:

$ sudo cp .cheat/hello /usr/share/cheat

Then try out your new cheat sheet:

$ cheat hello
Hello, World!
=============
For some reason, the world never says hello back, but saying "Hello, World!"
is something of a Unix/Linux tradition.

You can add cheat sheets for other commands or for scripts that you intend others to use to explain their options. Unlike man pages, cheat sheets just provide command examples, but often these are the most useful thing, especially for new users who don't want to struggle with all of a command's syntactical options explained in the associated man pages.

Join the Network World communities on Facebook and LinkedIn to comment on topics that are top of mind.
Related:

Copyright © 2021 IDG Communications, Inc.

SD-WAN buyers guide: Key questions to ask vendors (and yourself)