From 6b8ecd6b5cefbb290f4901d0d1e6aff9b907468d Mon Sep 17 00:00:00 2001 From: Chris Lane Date: Sun, 19 Oct 2014 11:43:43 -0400 Subject: [PATCH] Cherry-picking changes from #185 @zhujian0805 contributed some excellent cheatsheets in #185, but some binary files seem to have gotten mixed into the commit as well. This commit cherry-picks the cheatsheet file changes from that PR while leaving behind the cruft. Also performed minor editing on some of the cheatsheets. --- cheat/cheatsheets/du | 2 ++ cheat/cheatsheets/find | 6 +++--- cheat/cheatsheets/lvm | 7 +++++++ cheat/cheatsheets/nc | 20 ++++++++++++++++++++ cheat/cheatsheets/route | 30 +++++++++++++++++++++++++++--- cheat/cheatsheets/rsync | 12 ++++++++++-- cheat/cheatsheets/sed | 5 ++++- cheat/cheatsheets/snmpwalk | 5 +++++ 8 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 cheat/cheatsheets/du create mode 100644 cheat/cheatsheets/lvm create mode 100644 cheat/cheatsheets/nc create mode 100644 cheat/cheatsheets/snmpwalk diff --git a/cheat/cheatsheets/du b/cheat/cheatsheets/du new file mode 100644 index 0000000..61c625d --- /dev/null +++ b/cheat/cheatsheets/du @@ -0,0 +1,2 @@ +# To sort directories/files by size +du -sk *| sort -rn diff --git a/cheat/cheatsheets/find b/cheat/cheatsheets/find index 5cd262f..f97ce77 100644 --- a/cheat/cheatsheets/find +++ b/cheat/cheatsheets/find @@ -20,10 +20,10 @@ find ./path/ -name '*.txt' -exec rm '{}' \; find ./path/ -name '*.txt' | xargs grep 'string' # To find files with size bigger than 5 Mb and sort them by size: -find ./ -size +5M -type f -print0 | xargs -0 ls -Ssh +find . -size +5M -type f -print0 | xargs -0 ls -Ssh | sort -z # To find files bigger thank 2 MB and list them: -find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }' +find . -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }' # To find files modified more than 7 days ago and list file information find . -type f -mtime +7d -ls @@ -41,4 +41,4 @@ find . -maxdepth 2 -name build -type d find . ! -iwholename '*.git*' -type f # Find all files that have the same node (hard link) as MY_FILE_HERE -find / -type f -samefile MY_FILE_HERE 2>/dev/null +find . -type f -samefile MY_FILE_HERE 2>/dev/null diff --git a/cheat/cheatsheets/lvm b/cheat/cheatsheets/lvm new file mode 100644 index 0000000..492be2e --- /dev/null +++ b/cheat/cheatsheets/lvm @@ -0,0 +1,7 @@ +#Exclusive Activation of a Volume Group in a Cluster +#Link --> https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/High_Availability_Add-On_Administration/s1-exclusiveactive-HAAA.html +1> vgs --noheadings -o vg_name +2> volume_list = [ "rhel_root", "rhel_home" ] +3> dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r) +4> Reboot the node +5> uname -r to verify the correct initrd image diff --git a/cheat/cheatsheets/nc b/cheat/cheatsheets/nc new file mode 100644 index 0000000..8dc9b53 --- /dev/null +++ b/cheat/cheatsheets/nc @@ -0,0 +1,20 @@ +# To open a TCP connection to port 42 of host.example.com, using port 31337 as the source port, with a timeout of 5 seconds: +nc -p 31337 -w 5 host.example.com 42 + +# To open a UDP connection to port 53 of host.example.com: +nc -u host.example.com 53 + +# To open a TCP connection to port 42 of host.example.com using 10.1.2.3 as the IP for the local end of the connection: +nc -s 10.1.2.3 host.example.com 42 + +# To create and listen on a UNIX-domain stream socket: +nc -lU /var/tmp/dsocket + +# 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. +nc -x10.2.3.4:8080 -Xconnect host.example.com 42 + +# The same example again, this time enabling proxy authentication with username "ruser" if the proxy requires it: +nc -x10.2.3.4:8080 -Xconnect -Pruser host.example.com 42 + +# To choose the source IP for the testing using the -s option +nc -zv -s source_IP target_IP Port diff --git a/cheat/cheatsheets/route b/cheat/cheatsheets/route index 032dcac..5997ebd 100644 --- a/cheat/cheatsheets/route +++ b/cheat/cheatsheets/route @@ -1,5 +1,29 @@ -# Add a default gateway: +# To display routing table IP addresses instead of host names: +route -n + +# To add a default gateway: route add default gateway 192.168.0.1 -# Display routing table IP addresses instead of host names: -route -n +# To add the normal loopback entry, using netmask 255.0.0.0 and associated with the "lo" device (assuming this device was previously set up correctly with ifconfig(8)). +route add -net 127.0.0.0 netmask 255.0.0.0 dev lo + +# To add a route to the local network 192.56.76.x via "eth0". The word "dev" can be omitted here. +route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0 + +# To delete the current default route, which is labeled "default" or 0.0.0.0 in the destination field of the current routing table. +route del default + +# To add a default route (which will be used if no other route matches). All packets using this route will be gatewayed through "mango-gw". The device which will actually be used for that route depends on how we can reach "mango-gw" - the static route to "mango-gw" will have to be set up before. +route add default gw mango-gw + +# To add the route to the "ipx4" host via the SLIP interface (assuming that "ipx4" is the SLIP host). +route add ipx4 sl0 + +# To add the net "192.57.66.x" to be gateway through the former route to the SLIP interface. +route add -net 192.57.66.0 netmask 255.255.255.0 gw ipx4 + +# To install a rejecting route for the private network "10.x.x.x." +route add -net 10.0.0.0 netmask 255.0.0.0 reject + +# This is an obscure one documented so people know how to do it. This sets all of the class D (multicast) IP routes to go via "eth0". This is the correct normal configuration line with a multicasting kernel +route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0 diff --git a/cheat/cheatsheets/rsync b/cheat/cheatsheets/rsync index 617bf74..43343b6 100644 --- a/cheat/cheatsheets/rsync +++ b/cheat/cheatsheets/rsync @@ -1,6 +1,14 @@ -# copy files from remote to local, maintaining file propertires and sym-links (-a), zipping for faster transfer (-z), verbose (-v). +# To copy files from remote to local, maintaining file properties and sym-links (-a), zipping for faster transfer (-z), verbose (-v). rsync -avz host:file1 :file1 /dest/ rsync -avz /source host:/dest -# Copy files using checksum (-c), rather than time, to detect if the file has changed. (Useful for validating backups). +# Copy files using checksum (-c) rather than time to detect if the file has changed. (Useful for validating backups). rsync -avc /source/ /dest/ + +# Copy contents of /src/foo to destination: + +# This command will create /dest/foo if it does not already exist +rsync -auv /src/foo /dest + +# Explicitly copy /src/foo to /dest/foo +rsync -auv /src/foo/ /dest/foo diff --git a/cheat/cheatsheets/sed b/cheat/cheatsheets/sed index f60b269..e22c97a 100644 --- a/cheat/cheatsheets/sed +++ b/cheat/cheatsheets/sed @@ -10,5 +10,8 @@ echo 'It is daytime' | sed 's/day/night/g' # To remove leading spaces sed -i -r 's/^\s+//g' file.txt -# Remove empty lines and print results to stdout: +# To remove empty lines and print results to stdout: sed '/^$/d' file.txt + +# To replace newlines in multiple lines +sed ':a;N;$!ba;s/\n//g' file.txt diff --git a/cheat/cheatsheets/snmpwalk b/cheat/cheatsheets/snmpwalk new file mode 100644 index 0000000..90c86ea --- /dev/null +++ b/cheat/cheatsheets/snmpwalk @@ -0,0 +1,5 @@ +# To retrieve all of the variables under system for host zeus +snmpwalk -Os -c public -v 1 zeus system + +# To retrieve the scalar values, but omit the sysORTable for host zeus +snmpwalk -Os -c public -v 1 -CE sysORTable zeus system