Installation And Usage Of Cheat Sheet

Cheat Sheet

Cheat Sheet is an interactive application which provides different options in an easy understandable form. In this article, we are going to discuss about the Installation and usage of Cheat Sheet command.

To Install Cheat in Linux

It is necessary that our system should possess ' python' and ' pip' . So install Python and pip before starting with the ' cheat' installation.

To install Python

Run the following command to install Python.

On Debian based Systems
# apt-get install Python

On RedHat based Systems

[root@linuxhelp Desktop]# yum install python
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * epel: epel.mirror.net.in
 * extras: centos.excellmedia.net
 * rpmforge: mirror.oscc.org.my
 * updates: centos.excellmedia.net
Setting up Install Process
Resolving Dependencies
-->  Running transaction check
--->  Package python.x86_64 0:2.6.6-36.el6 will be updated
.
.
.

  Verifying  : python-2.6.6-36.el6.x86_64                                         4/6
  Verifying  : python-libs-2.6.6-36.el6.x86_64                                    5/6
  Verifying  : tkinter-2.6.6-36.el6.x86_64                                        6/6

Updated:
  python.x86_64 0:2.6.6-64.el6                                                        

Dependency Updated:
  python-libs.x86_64 0:2.6.6-64.el6           tkinter.x86_64 0:2.6.6-64.el6          

Complete!

Now the installation of Python is successfully completed.

To Install Pip

Run the following command to install Pip.

On Debian based Systems
# apt-get install python-pip

On RedHat based Systems

[root@linuxhelp Desktop]# yum install python-pip
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * epel: epel.mirror.net.in
 * extras: centos.excellmedia.net
 * rpmforge: mirror.oscc.org.my
 * updates: centos.excellmedia.net
Setting up Install Process
Resolving Dependencies
-->  Running transaction check
--->  Package python-pip.noarch 0:7.1.0-1.el6 will be installed
-->  Finished Dependency Resolution
.
.
.
Is this ok [y/N]: y
Downloading Packages:
python-pip-7.1.0-1.el6.noarch.rpm                              | 1.5 MB     00:04     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : python-pip-7.1.0-1.el6.noarch                                      1/1
  Verifying  : python-pip-7.1.0-1.el6.noarch                                      1/1

Installed:
  python-pip.noarch 0:7.1.0-1.el6                                                     

Complete!

Installation of Pip is completed successfully.

To download and install Cheat

First install git, by running the following command

On Debian based Systems
# apt-get install git

On RedHat based Systems

[root@linuxhelp Desktop]# yum install git
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * epel: epel.mirror.net.in
 * extras: centos.excellmedia.net
 * rpmforge: mirror.oscc.org.my
 * updates: centos.excellmedia.net
Setting up Install Process
Resolving Dependencies
-->  Running transaction check
--->  Package git.x86_64 0:1.7.1-4.el6_7.1 will be installed
-->  Processing Dependency: perl-Git = 1.7.1-4.el6_7.1 for package: git-1.7.1-4.el6_7.1.x86_64
.
.
.

  Verifying  : 1:perl-Error-0.17015-4.el6.noarch                                  2/3
  Verifying  : git-1.7.1-4.el6_7.1.x86_64                                         3/3

Installed:
  git.x86_64 0:1.7.1-4.el6_7.1                                                        

Dependency Installed:
  perl-Error.noarch 1:0.17015-4.el6         perl-Git.noarch 0:1.7.1-4.el6_7.1        

Complete!

Installation of git is successfully completed.

To install Python Dependencies

Run the following command to install Python dependencies.

[root@linuxhelp Desktop]# pip install docopt pygments
You are using pip version 7.1.0, however version 8.1.1 is available.
You should consider upgrading via the ' pip install --upgrade pip'  command.
Collecting docopt
  Downloading docopt-0.6.2.tar.gz
Collecting pygments
  Downloading Pygments-2.1.3-py2.py3-none-any.whl (755kB)
    100% |????????????????????????????????| 757kB 209kB/s 
Installing collected packages: docopt, pygments
  Running setup.py install for docopt
Successfully installed docopt-0.6.2 pygments-2.1.3

Run the following command to clone the Git repository.
# git clone https://github.com/chrisallenlane/cheat.git

[root@linuxhelp Desktop]# git clone https://github.com/chrisallenlane/cheat.git
Initialized empty Git repository in /root/Desktop/cheat/.git/
remote: Counting objects: 2587, done.
remote: Total 2587 (delta 0), reused 0 (delta 0), pack-reused 2587
Receiving objects: 100% (2587/2587), 450.85 KiB | 19 KiB/s, done.
Resolving deltas: 100% (1420/1420), done.

To Execute setup.py script

Go to cheat directory and execute the ' setup.py' script to install python.

[root@linuxhelp Desktop]# cd cheat
[root@linuxhelp cheat]# python setup.py install
/usr/lib64/python2.6/distutils/dist.py:266: UserWarning: Unknown distribution option: ' install_requires' 
  warnings.warn(msg)
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/cheat
copying cheat/__init__.py ->  build/lib/cheat
.
.
.
byte-compiling /usr/lib/python2.6/site-packages/cheat/test/__init__.py to __init__.pyc
running install_scripts
copying build/scripts-2.6/cheat ->  /usr/bin
changing mode of /usr/bin/cheat to 755
running install_egg_info
Writing /usr/lib/python2.6/site-packages/cheat-2.1.24-py2.6.egg-info


Now the installation of Cheat sheet is successfully completed.

To check a cheat version

After installing Cheat sheet, verify the cheat version by running the following command.

 [root@linuxhelp cheat]# cheat -v 
cheat 2.1.24

Configuration for Cheat

Add the following lines into the file ' ~/.bashrc' to set the EDITOR environment variable.

export EDITOR=/usr/bin/nano

Save the file and logout.

To enable autocompletion

To enable autocompletion, copy the ' cheat.bash' script into ' /etc/bash_completion.d' path.

[root@linuxhelp Desktop]# cp cheat/cheat/autocompletion/cheat.bash  /etc/bash_completion.d/

Add ' CHEATCOLORS' environment variable in your ' .bashrc' file, to activate syntax highlighting feature.

[root@linuxhelp Desktop]# export CHEATCOLORS=true

To make the application rich, add the cheat sheets to ~/.cheat/.

[root@linuxhelp Desktop]#  cheat -e xyz

The above command will open a ' xyz' cheat-sheet. If it is not available it creates a xyz cheat-sheet which will be opened in the default EDITOR.

Uses of cheat

Run the following command to list the usage of zip command.

[root@linuxhelp Desktop]# cheat zip
# Create zip file
zip archive.zip file1 directory/

# To list, test and extract zip archives, see unzip
cheat unzip

The following command will show the usage of ' df' command.

[root@linuxhelp Desktop]# cheat df
# Printout disk free space in a human readable format
df -h

Run the following command to show the usage of ' netstat' command.

[root@linuxhelp Desktop]# cheat netstat
# WARNING ! netstat is deprecated. Look below.

# To view which users/processes are listening to which ports:
sudo netstat -lnptu

# To view routing table (use -n flag to disable DNS lookups):
netstat -r

# Which process is listening to port 
netstat -pln | grep  | awk ' {print $NF}' 

Example output: 1507/python

# Fast display of ipv4 tcp listening programs
sudo netstat -vtlnp --listening -4

# WARNING ! netstat is deprecated.
# Replace it by:
ss

# For netstat-r
ip route

# For netstat -i
ip -s link

# For netstat-g
ip maddr

Run the following command to know the usage of ' systemctl' command.

[root@linuxhelp Desktop]# cheat systemctl
# List all loaded/active units
systemctl list-units

# Check the status of a service
systemctl status foo.service

# Start a service
systemctl start foo.service

# Restart a service
systemctl restart foo.service

# Stop a service
systemctl stop foo.service

# Reload a service' s configuration
systemctl reload foo.service

# Enable a service to startup on boot
systemctl enable foo.service

# Disable a service to startup on boot
systemctl disable foo.service

# List the dependencies of a service
# when no service name is specified, lists the dependencies of default.target
systemctl list-dependencies foo.service 

# List currently loaded targets
systemctl list-units --type=target

# Change current target
systemctl isolate foo.target

# Change default target
systemctl enable foo.target

To get a list of available commands

Run the following command to view the list of commands available.

[root@linuxhelp Desktop]# cheat -l
7z               /usr/lib/python2.6/site-packages/cheat/cheatsheets/7z
ab               /usr/lib/python2.6/site-packages/cheat/cheatsheets/ab
apk              /usr/lib/python2.6/site-packages/cheat/cheatsheets/apk
apparmor         /usr/lib/python2.6/site-packages/cheat/cheatsheets/apparmor
apt              /usr/lib/python2.6/site-packages/cheat/cheatsheets/apt
apt-cache        /usr/lib/python2.6/site-packages/cheat/cheatsheets/apt-cache
.
.
.
.
virtualenv       /usr/lib/python2.6/site-packages/cheat/cheatsheets/virtualenv
weechat          /usr/lib/python2.6/site-packages/cheat/cheatsheets/weechat
wget             /usr/lib/python2.6/site-packages/cheat/cheatsheets/wget
xargs            /usr/lib/python2.6/site-packages/cheat/cheatsheets/xargs
xrandr           /usr/lib/python2.6/site-packages/cheat/cheatsheets/xrandr
yaourt           /usr/lib/python2.6/site-packages/cheat/cheatsheets/yaourt
youtube-dl       /usr/lib/python2.6/site-packages/cheat/cheatsheets/youtube-dl
yum              /usr/lib/python2.6/site-packages/cheat/cheatsheets/yum
zip              /usr/lib/python2.6/site-packages/cheat/cheatsheets/zip
zoneadm          /usr/lib/python2.6/site-packages/cheat/cheatsheets/zoneadm

To search with specific keyword

When you search a command with the specific keyword, it lists all the possible options available with that command.

[root@linuxhelp Desktop]# cheat -s ssh
grep:
  # Add [] to the first letter. Ex: sshd ->  [s]shd

journalctl:
  # Filter by Command, e.g., sshd
  journalctl _COMM=sshd

nc:
 # To connect to port 42 of host.example.com via an HTTP proxy at 10.2.3.4, port 8080. This example could also be used by ssh(1)  see the ProxyCommand directive in ssh_config(5) for more information.

ps:
  # Add [] to the first letter. Ex: sshd ->  [s]shd

ss:
  # show all ssh related connection
  ss -t state established ' ( dport = :ssh or sport = :ssh )' 

ssh:
  # To ssh via pem file (which normally needs 0600 permissions):
  ssh -i /path/to/file.pem user@example.com
  ssh -p 2222 user@example.com
  ssh -A user@example.com
  ssh -t user@example.com ' the-remote-command' 
  ssh -X user@example.com
  ssh -f -L 8080:remote.example.com:5000 user@personal.server.com -N
  ssh -X -t user@example.com ' chromium-browser' 
  ssh -D 9999 user@example.com
  ssh user@example.com -C -c blowfish -X
  # Copy files and folders through ssh from remote host to pwd with tar.gz compression
  ssh user@example.com " cd /var/www/Shared/  tar zcf - asset1 asset2"  | tar zxf -

ssh-copy-id:
  ssh-copy-id username@host
  ssh-copy-id username@host -p 2222
  # To copy a key to a remote host on a non-standard port with non-standard ssh key:
  ssh-copy-id ~/.ssh/otherkey " username@host -p 2222" 

ssh-keygen:
  ssh-keygen -t rsa
  ssh-keygen -t rsa -b 4096
  ssh-keygen -p -P old_passphrase -N new_passphrase -f /path/to/keyfile
  ssh-keygen -p -P old_passphrase -N ' '  -f /path/to/keyfile
  ssh-keygen -t rsa -b 4096 -C " $USER@$HOSTNAME"  -P passphrase

tcpdump:
  # - port ssh

vagrant:
  vagrant ssh

To view the location

In order to know the location of a specific file or folder, run the following command.

[root@linuxhelp Desktop]# cheat -d
/root/.cheat
/usr/lib/python2.6/site-packages/cheat/cheatsheets

To copy the in-built cheat to your directory

Copy the in-built cheat, from ' /cheat/cheatsheets/' directory to ' /home/avi/.cheat/' directory.

[root@linuxhelpDesktop]# cp/usr/local/lib/python2.6/site-packages/cheat/cheatsheets/* /home/avi/.cheat/

Various interactive commands.

Run the following ' man mkdir' command to view the various options available.

Run the following ' help' option to list the available options.


[root@linuxhelp Desktop]# mkdir --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.
  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask
  -p, --parents     no error if existing, make parent directories as needed
  -v, --verbose     print a message for each created directory
  -Z, --context=CTX  set the SELinux security context of each created
                      directory to CTX
      --help     display this help and exit
      --version  output version information and exit

Report mkdir bugs to bug-coreutils@gnu.org
GNU coreutils home page: < http://www.gnu.org/software/coreutils/> 
General help using GNU software: < http://www.gnu.org/gethelp/> 
For complete documentation, run: info coreutils ' mkdir invocation' 

' whereis' command is used to know the location of the Binaries installed.

[root@linuxhelp Desktop]# whereis httpd
httpd: /usr/sbin/httpd /usr/sbin/httpd.event /usr/sbin/httpd.worker /etc/httpd /usr/lib64/httpd /usr/share/man/man8/httpd.8.gz

' whatis' command is used to display the short and one line options of a particular command.

[root@linuxhelp Desktop]# whatis cat
cat                  (1)  - concatenate files and print on the standard output
cat                  (1p)  - concatenate and print files
FAQ
Q
What is the command to list the available commands in the cheat?
A
The command used to list all the commands in cheat
Syntax: "cheat -v"
Q
What are the most important and required dependencies are?
A
Here the most required dependencies are "python and pip".
Q
What is the command to check the version of the cheat sheet?
A
To verify the cheat version by running the following command.
Syntax: "cheat -v "
Q
What is the essential use of a cheat sheet?
A
To be in an interactive application which provides different options in an easily understandable form.
Q
What are the python dependencies because even after the installation of pip and python am still facing error?
A
Use this command to install
Syntax: "pip install docopt pygments"
Install this and try again