Resolved a merge conflict and made a minor commenting change.

This commit is contained in:
Chris Lane 2013-09-14 10:13:54 -04:00
commit a07079957a
19 changed files with 354 additions and 9 deletions

View File

@ -63,6 +63,7 @@ Clone this repository and `cd` into it, then run
mkdir ~/.cheat
cp cheatsheets/* ~/.cheat
Modifying Cheatsheets
=====================
The value of `cheat` is that it allows you to create your own cheatsheets - the
@ -111,6 +112,8 @@ You may, of course, append multiple directories to your `CHEATPATH`:
export CHEATPATH=$CHEATPATH:/path/to/more/cheats
```
You may view which directories are on your `CHEATPATH` with `cheat -d`.
Enabling Syntax Highlighting
----------------------------
`cheat` can apply syntax highlighting to your cheatsheets if so desired. To
@ -140,12 +143,18 @@ Likewise, an existing cheatsheet may be edited via:
cheat -e foo
```
Command Autocompletion in zsh
-----------------------------
`zsh` users may use `cheat -d` in coordination with the provided `\_cheat` file
to implement autocompletion [as described here][4].
Contributing
============
If you would like to contribute cheetsheets or program functionality, please
fork this repository, make your chanages, and send me a pull request.
Related Projects
================
@ -166,3 +175,4 @@ Related Projects
[1]: https://github.com/lucaswerkmeister/cheats
[2]: https://github.com/jahendrie/cheat
[3]: http://errtheblog.com/posts/21-cheat
[4]: https://github.com/chrisallenlane/cheat/pull/77

24
cheat
View File

@ -1,6 +1,29 @@
#!/usr/bin/env python
"""
cheat.py -- 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.
Copyright (C) 2013, Chris Lane
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import sys
import argparse
import subprocess
from textwrap import dedent
@ -112,6 +135,7 @@ def help(cheatsheets):
def list_cheatsheets(cheatsheets):
"Lists the cheatsheets that are currently available"
max_command = max([len(x) for x in cheatsheets.keys()]) + 3
return ('\n'.join(sorted(['%s [%s]' % (key.ljust(max_command), value)
for key, value in cheatsheets.items()])))

18
cheatsheets/apparmor Normal file
View File

@ -0,0 +1,18 @@
# Desc: Apparmor will protect the system by confining programs to a limited set of resources.
# To activate a profile:
sudo aa-enforce usr.bin.firefox
# OR
export _PROFILE_='usr.bin.firefox' sudo $(rm /etc/apparmor.d/disable/$_PROFILE_ ; cat /etc/apparmor.d/$_PROFILE_ | apparmor_parser -a )
# TO disable a profile:
sudo aa-disable usr.bin.firefox
# OR
export _PROFILE_='usr.bin.firefox' sudo $(ln -s /etc/apparmor.d/$_PROFILE_ /etc/apparmor.d/disable/ && apparmor_parser -R /etc/apparmor.d/$_PROFILE_)
# To list profiles loaded:
sudo aa-status
# OR
sudo apparmor_status
# List of profiles aviables: /etc/apparmor.d/

13
cheatsheets/apt-get Normal file
View File

@ -0,0 +1,13 @@
# Desc: Allows to update the operating system
# To fetch package list
apt-get update
# To download and install updates without installing new package.
apt-get update
# To download and install the updates AND install new necessary packages
apt-get dist-upgrade
# Full command:
apt-get update && apt-get dist-upgrade

15
cheatsheets/aptitude Normal file
View File

@ -0,0 +1,15 @@
# To search for packages:
aptitude search "whatever"
# To display package records for the named package(s):
aptitude show pkg(s)
# To install a package:
aptitude install package
# To remove a package:
aptitude remove package
# To remove unnecessary package:
aptitude autoclean

17
cheatsheets/at Normal file
View File

@ -0,0 +1,17 @@
# To schedule a one time task
at {time}
{command 0}
{command 1}
Ctrl-d
# {time} can be either
now | midnight | noon | teatime (4pm)
HH:MM
now + N {minutes | hours | days | weeks}
MM/DD/YY
# To list pending jobs
atq
# To remove a job (use id from atq)
atrm {id}

36
cheatsheets/chmod Normal file
View File

@ -0,0 +1,36 @@
# Add execute for all (myscript.sh)
chmod a+x myscript.sh
# Set user to read/write/execute, group/global to read only (myscript.sh), symbolic mode
chmod u=rwx, go=r myscript.sh
# Remove write from user/group/global (myscript.sh), symbolic mode
chmod a-w myscript.sh
# Remove read/write/execute from user/group/global (myscript.sh), symbolic mode
chmod = myscript.sh
# Set user to read/write and group/global read (myscript.sh), octal notation
chmod 644 myscript.sh
# Set user to read/write/execute and group/global read/execute (myscript.sh), octal notation
chmod 755 myscript.sh
# Set user/group/global to read/write (myscript.sh), octal notation
chmod 666 myscript.sh
# Roles
u - user (owner of the file)
g - group (members of file's group)
o - global (all users who are not owner and not part of group)
a - all (all 3 roles above)
# Numeric representations
7 - full (rwx)
6 - read and write (rw-)
5 - read and execute (r-x)
4 - read only (r--)
3 - write and execute (-wx)
2 - write only (-w-)
1 - execute only (--x)
0 - none (---)

8
cheatsheets/chown Normal file
View File

@ -0,0 +1,8 @@
# Change file owner
chown user file
# Change file owner and group
chown user:group file
# Change owner recursively
chown -R user directory

View File

@ -2,6 +2,9 @@
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
# To set your editor:
git config --global core.editor emacs
# To enable color:
git config --global color.ui true

View File

@ -1,5 +1,11 @@
# Basic:
grep pattern file
# case nonsensitive research:
grep -i pattern file
# Recursively grep for string <pattern> in folder:
grep -R pattern folder
# Getting pattern from file (one by line):
grep -f pattern_file file

13
cheatsheets/ifconfig Normal file
View File

@ -0,0 +1,13 @@
# Display network settings of the first ethernet adapter
ifconfig wlan0
# Display all interfaces, even if down
ifconfig -a
# Take down / up the wireless adapter
ifconfig {up|down} wlan0
# Set a static IP and netmask
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
# You may also need to add a gateway IP
route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

View File

@ -3,3 +3,9 @@ sudo netstat -lnptu
# To view routing table (use -n flag to disable DNS lookups):
netstat -r
# Which process is listening to port <port>
netstat -pln | grep <port> | awk '{print $NF}'
Example output: 1507/python

43
cheatsheets/pacman Normal file
View File

@ -0,0 +1,43 @@
# All the following command work as well with multiple package names
# To search for a package
pacman -Ss <package name>
# To update the local package base and upgrade all out of date packages
pacman -Suy
# To install a package
pacman -S <package name>
# To uninstall a package
pacman -R <package name>
# To uninstall a package and his depedencies, removing all new orphans
pacman -Rcs <package name>
# To get informations about a package
pacman -Si <package name>
# To install a package from builded package file (.tar.xz)
pacman -U <file name/file url>
# To list the commands provided by an installed package
pacman -Ql <package name> | sed -n -e 's/.*\/bin\///p' | tail -n +2
# To list explicitly installed packages
pacman -Qe
# To list orphan packages (installed as dependencies and not required anymore)
pacman -Qdt
# You can't directly install packages from the Arch User Database (AUR) with pacman.
# You need yaourt to perform that. But considering yaourt itself is in the AUR, here is how to
build a package from its tarball.
# First, get the .tar.gz archive and unpack it
wget <archive url>
tar -xzf <archive file>
cd <unpacked folder>
# Then build the package and install it
makepkg -s
pacman -U <package file (.pkg.tar.xz)>

11
cheatsheets/screen Normal file
View File

@ -0,0 +1,11 @@
# Start a new named screen session:
screen -S session_name
# Detach from the current session:
Press Ctrl+A then press d
# Re-attach a detached session:
screen -r session_name
# List all screen sessions:
screen -ls

View File

@ -10,5 +10,5 @@ echo 'It is daytime' | sed 's/day/night/g'
# To remove leading spaces
sed -i -r 's/^\s+//g' file.txt
# To remove empty lines
cat file.txt | sed '/^$/d'
# Remove empty lines and print results to stdout:
sed '/^$/d' file.txt

11
cheatsheets/sort Normal file
View File

@ -0,0 +1,11 @@
# To sort a file:
sort file
# To sort a file by keeping only unique:
sort -u file
# To sort a file and reverse the result:
sort -r file
# To sort a file randomly:
sort -R file

41
cheatsheets/tmux Normal file
View File

@ -0,0 +1,41 @@
# Start tmux:
tmux
# Detach from tmux:
Ctrl-b d
# Restore tmux session:
tmux attach
# Display session:
tmux ls
# Start a shared session:
tmux -S /tmp/your_shared_session
chmod 777 /tmp/your_shared_session
# Help screen (Q to quit):
Ctrl-b ?
# Scroll in window:
Ctrl-b PageUp/PageDown
# Window management
# =================
# Create window:
Ctrl-b c
# Destroy window:
Ctrl-b x
# Switch between windows:
Ctrl-b [0-9]
or
Ctrl-b Arrows
# Split windows horizontally:
Ctrl-b %
# Split windows vertically:
Ctrl-b "

View File

@ -1,8 +1,55 @@
# Appending
a - drops vim into append mode
i - enters append mode without character skip
# File management
:w - writes (saves) file
:q - quits
;q! - quits without saving changes
:e reload file
:q quit
:q! quit without saving changes
:w write file
:w {file} write new file
:x write file and exit
# Movement
k
h l basic motion
j
w next start of word
w next start of whitespace-delimited word
e next end of word
E next end of whitespace-delimited word
b previous start of word
B previous start of whitespace-delimited word
0 start of line
$ end of line
# Insertion
# To exit from insert mode use Esc or Ctrl-C
# Enter insertion mode and:
a append after the cursor
A append at the end of the line
i insert before the cursor
I insert at the beginning of the line
o create a new line under the cursor
O create a new line above the cursor
R enter insert mode but replace instead of inserting chars
:r {file} insert from file
# Editing
u undo
yy yank (copy) a line
y{motion} yank text that {motion} moves over
p paste after cursor
P paste before cursor
<Del> or x delete a character
dd delete a line
d{motion} delete text that {motion} moves over
# Preceding a motion or edition with a number repeats it n times
# Examples:
50k moves 50 lines up
2dw deletes 2 words
5yy copies 5 lines

23
cheatsheets/yaourt Normal file
View File

@ -0,0 +1,23 @@
# All pacman commands are working the same way with yaourt.
# Just check the pacman cheatsheet.
# For instance, to install a package :
pacman -S <package name>
yaourt -S <package name>
# The difference is that yaourt will also query the Arch User Repository,
# and if appropriate, donwload the source and build the package requested.
# Here are the commands yaourt provides while pacman doesn't :
# To search for a package and install it
yaourt <package name>
# To update the local package base and upgrade all out of date package, including the ones from
AUR and the packages based on development repos (git, svn, hg...)
yaourt -Suya --devel
# For all of the above commands, if you want yaourt to stop asking constantly for confirmations,
use the option --noconfirm
# To build a package from source
yaourt -Sb <package name>