Home ICOs How to Get a Cheatsheet for Any Command in the Linux Terminal

How to Get a Cheatsheet for Any Command in the Linux Terminal


Ever wanted a cheat code for writing Linux commands without consulting the manpages every time and understanding their usage? Well, there’s a tool for that called cheat. Whether you need a quick refresher or want to get familiar with a new command, cheat is the tool to guide you.

There’s a cheat Command in Linux

Cheat is a Linux tool created using Go. It uses community-sourced Linux command cheatsheets to display common examples of that command being used. It can be handy when you need to get a quick overview of a command.

Say you use the sed command a lot. Now, it has many options. Reading the manpages doesn’t always help. And searching on the internet for your specific use case can also feel time-consuming. In such scenarios, you can use the cheat command to see some common use cases of sed with practical examples.

Installing and Configuring cheat on Linux

Let’s see how you can install it on your Linux system. For the demonstration, I’ll be using Ubuntu 24.04 LTS. But the commands I show apply to other Linux distros too. To install cheat, you can use a one-liner installation command below. Before running the command, make sure to check the GitHub release page and use the latest version (it’s 4.4.2 for me) as well as the correct package for your system in the command.

        cd /tmp \

&& wget https:

&& gunzip cheat-linux-amd64.gz \

&& chmod +x cheat-linux-amd64 \

&& sudo mv cheat-linux-amd64 /usr/local/bin/cheat

Installing cheat on Linux from GitHub.

The command downloads the package, unzips it, gives it executable permission, and moves it to the “/usr/local/bin” directory.

If you have Go installed, you can also use it to install cheat.

go install github.com/cheat/cheat/cmd/cheat@latest

There are also community-maintained packages that you can install via a package manager. For example, if you have Snap enabled, you can install it with:

sudo snap install cheat

To verify the installation, you can run:

cheat --version

After successfully installing cheat, you need to do three things:

  1. Generate a configuration file
  2. Configure cheatpaths
  3. Download the Community cheatsheets.

Fortunately, all of these will be done automatically when you run cheat for the first time.

Configuring cheat by running it for the first time.

The configuration file has been generated in the “~/.config/cheat” directory. It’s a YAML file. It has all the necessary configurations you’ll need to get a good experience using cheat. If you want to change anything, this is the file to look for.

cheat configuration file conf.yml.

You can also change the default path for the configuration file using environment variables.

export CHEAT_CONFIG_PATH="~/.dotfiles/cheat/conf.yml"

The cheatsheets are simple text files with the name of the command the cheatsheet is for. For example, the cheatsheet for the cd command is a file that contains a list of cheats for the cd command. By default, the cheat command doesn’t come with any cheatsheet. Rather, it uses the community cheatsheets you’re asked to download on the first run.

These cheatsheets are located in cheatpaths, a collection of directories where your cheatsheets reside. You can configure cheatpaths in the conf.yml file to add more paths or change the current ones.

The cheat command supports auto-completion. However, it’s only available for bash, fish, and zsh. You can also integrate with fzf. To do that, first make fzf available on your PATH. Then run:

export CHEAT_USE_FZF=true

That covers the basic setup you will need for cheat. Of course, there’s much more you can do.

How to Use cheat

Now let’s have a look at how you can use the cheat command to get cheatsheets for other Linux commands. Let’s go back to our previous example, the sed command. To get its cheatsheet, simply run:

cheat sed
A cheatsheet for the sed command displayed in the Linux terminal.

The output shows you some good examples of how to use the sed command in which case. Unlike the manpage, you don’t have to manually figure it out. You can just take an example, modify it as per your needs, and run the command. If you want to view all current available cheatsheets, run:

cheat -l
Listing all available cheatsheets in the terminal.

It lists all commands that have a cheatsheet, their location, and tags. Tags are categories that a command is related to. You can also view cheatsheets of a certain tag. For example, if you want to view available cheatsheets tagged with ‘packaging’, run:

cheat -l -t packaging
Listing cheatsheets tagged with packaging in the terminal.

This allows you to check the available cheatsheets for commands of a certain type. You can also view cheatsheets by path. By default, there’s a “community” path and a “personal” path.

cheat -l -p personal
cheat -l -p community

You can also search for phrases in the cheatsheets by adding the -s flag.

cheat -s directory
Searching for the phrase directory among the cheatsheets using the cheat command.

You can also use regex for searching. This example searches for IP addresses.

cheat -r -s '(?:[0-9]{1,3}\.){3}[0-9]{1,3}'
Using regex search in the cheat command.

Here, we can see that the displayed cheatsheets have IP addresses matching our regex. You can also combine the flags to make your search narrower and more targeted.

cheat -p community -t networking --regex -s '(?:[0-9]{1,3}\.){3}[0-9]{1,3}'
Combining multiple flags in the cheat command to list targeted cheatsheets.

In this example, we’re searching for cheatsheets in the community path that are tagged with “networking” and have the regex for IP addresses.

Managing Cheatsheets

Cheatsheets are the heart of the cheat command. The better you can manage and organize your cheatsheets, the easier it will be for you to find the correct one. A great thing is that you can download the community cheatsheets in the initial setup. In case you skipped that, you can still download it later from GitHub.

git clone https://github.com/cheat/cheatsheets.git ~/.config/cheat/cheatsheets/community

The same goes for the configuration file.

cd ~/.config/cheat
curl -LO https://raw.githubusercontent.com/cheat/cheat/master/configs/conf.yml

Since cheat uses cheatsheets from the community, you shouldn’t expect it to have a cheatsheet for every single Linux command or tool. However, you can create your own cheatsheets.

To create a cheatsheet, run:

cheat -e 

For demonstration, I’m creating a cheatsheet for the ripgrep command.

cheat -e ripgrep

If there’s no cheatsheet available for that command, it will take you to an empty file in a text editor. Type your text here and save the file. Here’s an example cheatsheet I made for the ripgrep command. You should try to follow the same style.

        
tags: [ files, search ]


rg pattern>


rg -i pattern>


rg pattern> -t type>


rg -l pattern>


rg -n pattern>


rg -w pattern>


rg patternpath>


rg -C linespattern>


rg -uu pattern>


rg --no-ignore pattern>


rg regex-pattern>


rg -c pattern>

After saving it, you can call the command to view its cheatsheet.

Creating a custom cheatsheet for the ripgrep command using cheat.

If you want to edit an existing cheatsheet, you can use the same -e flag. It will open the file that contains the cheatsheet for that command. This allows you to add your own notes or command use cases.

The creators of the cheat command have a Bash script that allows you to easily maintain your cheatsheets. Review the cheatsheet maintenance script first. If you want to download and run it, use these commands:

        curl -LO https:

sudo chmod +x cheatsheets

sudo mv cheatsheets /usr/local/bin/

With this script, you can update the community cheatsheets you have. Moreover, you can also push your own cheatsheets to remote repositories like GitHub.


If you have a hard time remembering Linux commands, cheat is a great tool for a quick peek. It’s not the only tool for this purpose, though. There’s another tool named tldr that does something similar. Having such tools is a great way to master new Linux commands.



Source link