Sweet Commands

I have this knote on my desktop that I use to keep track of commands I use often, but not frequently enough to remember by heart. Its gets fairly long, and is invaluable for me in my daily internet building tasks. I occasionally clean it out, removing things I never use, have found better solutions for, or I just remember now without a reference to prompt me. I decided this time I should share some of these items so that others may reap the benefits of my collecting. Enjoy!

# synflood listing (bash)
netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'
# current port 80 connections (bash)
netstat -an | grep :80 | sort
# bash for next loop
for i in `locate php~`;do echo $i;done
# sed text replace (bash)
sed -e s/$IN/$OUT/g $FILE > $NEWFILE
# ssh forward port 2525 to port 25 (bash)
ssh -NfC -R 2525:
this is useful to provide clients a way to connect to your smtp server when their local port 25 is blocked. It’s even easier to use rinetd.
# forward port 2525 to port 25 (rinetd.conf entry) 2525 25
**note! do not forward to an IP address that is in your ‘mynetworks’ entry in your postfix main.cf file, otherwise you will open a relay on port 2525 because postfix will see the mail coming in from there and not the originating IP.
# mail from command line (bash)
mail -s "Advomatic Test Email" -r from@advomatic.com to@advomatic.com
# new mysql user (sql)
grant all privileges on database.* to username@'192.168.1.%' identified by 'password'; flush privileges;
# mysql update across tables (sql)
UPDATE destination_table fd, source_table fs SET fd.options=fs.options WHERE fs.id=14 AND fd.id=5;
# mod_rewrite image redirect by referrer (apache conf or .htaccess)
RewriteCond %{HTTP_REFERER} ^http://hotlinker.blogspot.com/ [NC]
RewriteRule .(jpe?g|gif|bmp|png)$ unseemlyimages/holyhell.gif [L]

this is a fun trick for punishing hotlinkers 😉
# find the big files (bash)
find / -type f -size +1000000k
# find duplicate records (sql)
SELECT mail, COUNT(mail) AS totalcount FROM users GROUP BY mail HAVING (COUNT(mail) > 1);
# vi find / replace a term throughout a file
a great vi cheatsheet is here
# cvs drupal module checkout with branch specified
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-4-7 -d destination/directory contributions/modules/modulename
more here
# vi – get rid of stupid OSX ^M characters (be sure to use “CTRL-V CTRL-M” to make the ^M character)
got this here
# heartbeat haresources subnet config
node1 IPaddr::
node2 IPaddr::

this is useful for setting up multiple heartbeat node pairs on the same physical network so they wont complain about each other’s broadcast messages. more here