diff --git a/README.md b/README.md index 6cbfeb9..1457dd4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cheat b/cheat index 7cca84c..c7e1b8e 100755 --- a/cheat +++ b/cheat @@ -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 . +""" + 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()]))) diff --git a/cheatsheets/apparmor b/cheatsheets/apparmor new file mode 100644 index 0000000..3e6d337 --- /dev/null +++ b/cheatsheets/apparmor @@ -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/ diff --git a/cheatsheets/apt-get b/cheatsheets/apt-get new file mode 100644 index 0000000..0f4bcd6 --- /dev/null +++ b/cheatsheets/apt-get @@ -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 diff --git a/cheatsheets/aptitude b/cheatsheets/aptitude new file mode 100644 index 0000000..a837979 --- /dev/null +++ b/cheatsheets/aptitude @@ -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 + diff --git a/cheatsheets/at b/cheatsheets/at new file mode 100644 index 0000000..2827a45 --- /dev/null +++ b/cheatsheets/at @@ -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} diff --git a/cheatsheets/chmod b/cheatsheets/chmod new file mode 100644 index 0000000..31c5eb7 --- /dev/null +++ b/cheatsheets/chmod @@ -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 (---) diff --git a/cheatsheets/chown b/cheatsheets/chown new file mode 100644 index 0000000..811a864 --- /dev/null +++ b/cheatsheets/chown @@ -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 diff --git a/cheatsheets/git b/cheatsheets/git index d0e7c80..fb5a1c7 100644 --- a/cheatsheets/git +++ b/cheatsheets/git @@ -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 diff --git a/cheatsheets/grep b/cheatsheets/grep index 70fa3de..cd79eb5 100644 --- a/cheatsheets/grep +++ b/cheatsheets/grep @@ -1,5 +1,11 @@ # Basic: grep pattern file +# case nonsensitive research: +grep -i pattern file + # Recursively grep for string in folder: grep -R pattern folder + +# Getting pattern from file (one by line): +grep -f pattern_file file diff --git a/cheatsheets/ifconfig b/cheatsheets/ifconfig new file mode 100644 index 0000000..ca0b9d1 --- /dev/null +++ b/cheatsheets/ifconfig @@ -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 diff --git a/cheatsheets/netstat b/cheatsheets/netstat index caba5be..72fbc07 100644 --- a/cheatsheets/netstat +++ b/cheatsheets/netstat @@ -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 +netstat -pln | grep | awk '{print $NF}' + +Example output: 1507/python + diff --git a/cheatsheets/pacman b/cheatsheets/pacman new file mode 100644 index 0000000..353f6c5 --- /dev/null +++ b/cheatsheets/pacman @@ -0,0 +1,43 @@ +# All the following command work as well with multiple package names + +# To search for a package +pacman -Ss + +# To update the local package base and upgrade all out of date packages +pacman -Suy + +# To install a package +pacman -S + +# To uninstall a package +pacman -R + +# To uninstall a package and his depedencies, removing all new orphans +pacman -Rcs + +# To get informations about a package +pacman -Si + +# To install a package from builded package file (.tar.xz) +pacman -U + +# To list the commands provided by an installed package +pacman -Ql | 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 +tar -xzf +cd +# Then build the package and install it +makepkg -s +pacman -U diff --git a/cheatsheets/screen b/cheatsheets/screen new file mode 100644 index 0000000..cc2d3e4 --- /dev/null +++ b/cheatsheets/screen @@ -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 diff --git a/cheatsheets/sed b/cheatsheets/sed index 5d97e4a..f60b269 100644 --- a/cheatsheets/sed +++ b/cheatsheets/sed @@ -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 diff --git a/cheatsheets/sort b/cheatsheets/sort new file mode 100644 index 0000000..4c243ba --- /dev/null +++ b/cheatsheets/sort @@ -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 diff --git a/cheatsheets/tmux b/cheatsheets/tmux new file mode 100644 index 0000000..e9b76ce --- /dev/null +++ b/cheatsheets/tmux @@ -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 " diff --git a/cheatsheets/vim b/cheatsheets/vim index 3b79d77..fca5bbd 100644 --- a/cheatsheets/vim +++ b/cheatsheets/vim @@ -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 + 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 diff --git a/cheatsheets/yaourt b/cheatsheets/yaourt new file mode 100644 index 0000000..f3a6ec1 --- /dev/null +++ b/cheatsheets/yaourt @@ -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 +yaourt -S +# 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 + +# 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 +