Sep 092013
 

Cheat allows you to create and view interactive cheatsheets on the command-line. It was designed to help remind *nix system administrators of options for commands that they use frequently, but not frequently enough to remember. *Depends only on python.

cheat

Examples

The next time you’re forced to disarm a nuclear weapon without consulting Google, you may run:

cheat tar

You will be presented with a cheatsheet resembling:

# To extract an uncompressed archive:
tar -xvf /path/to/foo.tar

# To extract a .gz archive:
tar -xzvf /path/to/foo.tgz

# To create a .gz archive:
tar -czvf /path/to/foo.tgz /path/to/foo/

# To extract a .bz2 archive:
tar -xjvf /path/to/foo.tgz

# To create a .bz2 archive:
tar -cjvf /path/to/foo.tgz /path/to/foo/

To see what cheatsheets are availble, run cheat with no arguments.

Note that, while cheat was designed primarily for *nix system administrators, it is agnostic as to what content it stores. If you would like to use cheat to store notes on your favorite cookie recipes, feel free.
Installing
Installing Python for all users (requires root)


# apt-get install Python (On Debian based Systems)
# yum install python (On RedHat based Systems)

Install Pip

# apt-get install python-pip (On Debian based Systems)
# yum install python-pip (On RedHat based Systems)

Installing in your home directory

Download and Install Cheat
We will be downloading ‘cheat’ from Git. Make sure you have package ‘git’ installed, if not better install this first.

# apt-get install git (On Debian based Systems)
# yum install git (On RedHat based Systems)

Next, install the required python dependencies by running following command.
# pip install docopt pygments
Now, clone the Git repository of cheat.
# git clone https://github.com/chrisallenlane/cheat.git
Move to the cheat directory and run ‘setup.py‘ (a python script).
# cd cheat
# python setup.py install

If installation goes smoothly, you should be able to see a cheat version installed on the system.
# cheat -v
cheat 2.0.9

(This was installed to my/usr/local/lib/python2.7/dist-packages/cheat directory )

 
Here are the currently installed commands for Cheat: (ignore the _init__.py & __init__.pyc files)

$ls cheatsheets/
7z bash diff history ls od screen strace wget
ab chmod distcc ifconfig lsof openssl sed systemctl xargs
apk chown emacs indent markdown pacman shred tail yaourt
apparmor convert find __init__.py mkdir pdftk sockstat tar youtube-dl
apt-cache crontab gcc __init__.pyc mount php sort tcpdump yum
apt-get curl gdb iptables mysql ps split tee
aptitude cut git irssi mysqldump python sqlmap tmux
asciiart date gpg iwconfig ncat rm ssh top
asterisk dd grep journalctl netstat rsync ssh-copy-id truncate
at df gs less nmap sam2p ssh-keygen uname
awk dhclient head ln notify-send scp stdout vim

 

Required Configuration for Cheat

You must have an ‘EDITOR‘ environment variable set in ‘~/.bashrc’ file. Open the user ‘.bashrc‘ file and add the following line to it.

export EDITOR =/usr/bin/nano

You can use your favourite editor here in place of ‘nano‘. Save the file and logout. Again Login to make the changes taken into effect.

Next, add the cheat autocompletion feature to enable command-line autocompletion for different shells. To enable autocompletion, simply clone the ‘cheat.bash‘ script and copy the script to the appropriate path in your system.

# wget https://github.com/chrisallenlane/cheat/raw/master/cheat/autocompletion/cheat.bash 
# mv cheat.bash /etc/bash_completion.d/

NOTE: The team has uploaded other shell’s auto completion scrip to Git, which may be cloned and used in case of respective Shell. Use the following link for other shell’s auto completion script.

  1. Auto Completion Script for Various Shells

Optionally, you can also enable syntax highlighting, if desired. To active syntax highlighting feature, add a CHEATCOLORS environment variable in your ‘.bashrc‘ file.

export CHEATCOLORS=true

The Cheat application default program only serves the basic and most used commands. The content of cheat-sheet resides at location ~/.cheat/. Manual Cheatsheets can be added to this location to make the application rich.

# cheat -e xyz

This will open xyz cheat-sheet if available. If not it will create one. The cheat-sheet will be opened in the default EDITOR, we set in .bashrc in the configuration stage, above.

Usage of Cheat with Some Commands

A tarball may be *.gz or *.bz2 or *.zip or *.xz. So, what option to be used where?

Linux Tar Command

I never run dd command, no matter how much sure I am about the command before consulting and cross checking it at more than one location. The things seems to be easy now.

Linux dd Command

A ‘uname‘ command help.

Linux uname Command

A short ifconfig command line tutorial, in action.

Linux ifconfig Command

A ‘top‘ command, one of the most important command for Admin and Normal User.

Linux top Command

How about Cheating the cheat command (though the other sense)? Get a list of available commands, the cheat-sheet of which is installed in the System.

List All Linux Commands

Search Cheat-sheet with specific keyword.

Search Cheat Sheet

See the location of built-in cheat-sheets for all the commands.

$ cheat -d 

/home/avi/.cheat 
/usr/local/lib/python2.7/dist-packages/cheat/cheatsheets

Copy the in-built cheat-sheet to your native directory.

# cp /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/* /home/avi/.cheat/

 

 Posted by at 1:16 pm

Sorry, the comment form is closed at this time.