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$ ls7z csplit head mutt pip snmpwalk treeab cups hello mv pkcon socat truncateacl curl hg mysql pkgtools sockstat udisksctlalias cut history mysqldump pkill sort ulimitansi date http nc popd split unameapk dd hub ncat ps sport uniqapparmor deb iconv ncdu psql sqlite3 unzipapt df ifconfig netstat pushd sqlmap urpmapt-cache dhclient indent nkf pwd ss vagrantapt-get diff ip nmap python ssh vimaptitude distcc iptables nmcli r2 ssh-add virtualenvaria2c dnf irssi notify-send rcs ssh-copy-id wcasciiart docker iwconfig nova readline ssh-keygen weechatasterisk dpkg journalctl npm rename stdout wgetat du jq ntp rm strace xargsawk emacs jrnl numfmt route su xmltobash export kill od rpm sudo xrandrbower ffmpeg less openssl rpm2cpio svn xxdbzip2 find lib org-mode rss2email systemctl yaourtcat fkill ln p4 rsync systemd youtube-dlcd for ls pacman sam2p tail yumcheat gcc lsblk pass scd tar zchmod gdb lsof paste scp tarsnap zfschown git lvm patch screen tcpdump zipcomm gpg man pdftk sed tee zoneadmconvert grep markdown perl shred tidy zshcp gs mdadm pgrep shutdown tmuxcpdf gyb mkdir php slurm topcrontab 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.
Copyright © 2021 IDG Communications, Inc.