Cheatsheets

All posts tagged Cheatsheets

Today, was working on iptables, and accidently mistyped and typed in iptab..well found a pretty nifty tool.  Nothing fancy but should save me from using google to look up CIDR info

+———————————————-+
| addrs   bits   pref   class  mask            |
+———————————————-+
|     1      0    /32          255.255.255.255 |
|     2      1    /31          255.255.255.254 |
|     4      2    /30          255.255.255.252 |
|     8      3    /29          255.255.255.248 |
|    16      4    /28          255.255.255.240 |
|    32      5    /27          255.255.255.224 |
|    64      6    /26          255.255.255.192 |
|   128      7    /25          255.255.255.128 |
|   256      8    /24      1C  255.255.255.0   |
|   512      9    /23      2C  255.255.254.0   |
|    1K     10    /22      4C  255.255.252.0   |
|    2K     11    /21      8C  255.255.248.0   |
|    4K     12    /20     16C  255.255.240.0   |
|    8K     13    /19     32C  255.255.224.0   |
|   16K     14    /18     64C  255.255.192.0   |
|   32K     15    /17    128C  255.255.128.0   |
|   64K     16    /16      1B  255.255.0.0     |
|  128K     17    /15      2B  255.254.0.0     |
|  256K     18    /14      4B  255.252.0.0     |
|  512K     19    /13      8B  255.248.0.0     |
|    1M     20    /12     16B  255.240.0.0     |
|    2M     21    /11     32B  255.224.0.0     |
|    4M     22    /10     64B  255.192.0.0     |
|    8M     23     /9    128B  255.128.0.0     |
|   16M     24     /8      1A  255.0.0.0       |
|   32M     25     /7      2A  254.0.0.0       |
|   64M     26     /6      4A  252.0.0.0       |
|  128M     27     /5      8A  248.0.0.0       |
|  256M     28     /4     16A  240.0.0.0       |
|  512M     29     /3     32A  224.0.0.0       |
| 1024M     30     /2     64A  192.0.0.0       |
| 2048M     31     /1    128A  128.0.0.0       |
| 4096M     32     /0    256A  0.0.0.0         |
+———————————————-+

To copy fields 3 and 7 from input to output (3 string, 7 float):
awk ‘{printf”%s\t%10.4f\n”, $3, $7}’ < input > output
———-
To add a column of numbers:
awk ‘{sum=sum+$1;printf(“sum: %d\n”, sum)}’ < input | tail -1
———-
To calc the average of numbers in a file:
egrep “^:2″ *out | egrep total | cut -c44- | \
awk ‘{sum += $1;total += 1;printf”avg = %.4f\n”, sum/total}’ | \
tail -1
———-
To find ‘word’ in files owned by ‘username’ from location ‘.’:
find . -user username -print -exec \grep word ‘{}’ \; > output &
———-
To find all files that do not end in ‘pdb’ in location ‘.’:
find . \( ! -name \*pdb \) -print
———-
To find all files that do not end in ‘pdb’ in location ‘.’ and execute a
command on each file found:
find . \( ! -name \*pdb \) -exec \anneal2pdb ‘{}’ \;
———-
To remove all files ‘garb’:
find ~ -name garb -print -exec \rm ‘{}’ \;
———-
To report the file size of all files bigger than 2 meg and older than 30
days.
find . -type f -size +4096 -atime +30 -exec \du -sk ‘{}’ \;
———-
To search with a wildcard:
find . -name goob\* -print
———-
To manually nudge NFS:
umount /iris1/a (or whatever)
mount -a -t nfs
exportfs -a -v
———-
To encrypt the file ‘input’ to a file ‘output’:
crypt < input > output
enter key: (enter a password)
To decrypt the file ‘output’ to a file ‘done’:
crypt < output > done
enter key: (enter the password used to encrypt ‘output’)
———-
To convert tabs to spaces:
expand -tabstop filename.in > filename.out
eg
expand -3 garb > garb.out
will convert tabs to three spaces

To convert spaces to tabs:
unexpand filename
———-
To check the print que:
lpq
To remove a print job:
lprm <job # from lpq>
To check the printer:
lpc
———-
To remove duplicate lines from a file:
uniq filename > out
———-
To mail to compuserve:
If the username is ‘70000,200’, mail to:
mail 70000.200@compuserve.com
note the period instead of the comma.
To mail from compuserve:
>INTERNET Loopy@cup.portal.com
———-
To create a text file from a manual page:
man command | expand > file
vi file
:1,$s/.^V^H//g
😡
———-
To compare two files:
Flags 1, 2, or 3 suppress printing of the corresponding column. Thus
comm -12 prints only the lines common to the two files; comm -23 prints
only lines in the first file but not in the second; comm -123 prints
nothing.
———-
To run a string of commands over and over:
csh> sh
$ while :
> do
> command
> command
> done
When done, ^C to quit. ^D to return to csh.
———-
To get a list of ‘fsu.edu’ machines:
UNIX> nslookup
> ls fsu.edu > file
> exit
———-
To get a machine name from an IP address:
UNIX> nslookup
> set type=ptr
> 34.12.186.128.in-addr.arpa
Server: magnet.fsu.edu
Address: 146.201.250.2

34.12.186.128.in-addr.arpa name = weirdscience.chem.fsu.edu
———-
To add line numbers to the beggining of a file:
grep -n . input > output
or
paste x y > z
———-
To move (or copy) a directory heirarchy:
cd fromdir
tar cf – . | (cd todir; tar xfBp -)
———-
To copy a directory heirarchy exactly:
cd fromdir; tar cBf – . | (cd todir; tar xpBf -)
———-
To restart the sendmail process:
kill the original process
/usr/lib/sendmail -bd -q1h
———-
To alias rm so that it lists the files to be removed and asks for
confirmation:
alias rm \
‘/bin/ls -AsF \!* && echo -n “Remove? ” && if ($< == y) /bin/rm -rf \!*’
———-
To remove blank lines from a file:
sed -e ‘/^$/d’ file.in > file.out
———-