Linux

MySQL via PHP Cheat Sheet

Connect to MySQL and to the database // Connect to MySQL $connect = mysql_connect(“localhost”, “mysqluser”, “userpassword”) or die(mysql_error()); // Select the database mysql_select_db(“databasename”, $connect) or die(mysql_error()); PHP Manual Reference us2.php.net/manual/en/function.mysql-connect.php Close connection // Use the variable that was used to connect to MySQL mysql_close($connect) or die(mysql_error()); // PHP Manual Reference: us2.php.net/manual/en/function.mysql-close.php Create a database mysql_create_db(“dbname”) […]

Read More
Linux

regex –make option

Get a ready regex The –make option is described by its author as “a remedy for headaches.” It outputs a regexp for one of several common patterns that are given as arguments, as listed in table. List of ready regexps available in txt2regex Argument Description date This argument matches dates in mm/dd/yyyy format, from 00/00/0000 […]

Read More
Linux

A-Z index of the linux Bash

alias Create an alias awk Find and Replace text within file(s) break Exit from a loop builtin Run a shell builtin cal Display a calendar case Conditionally perform a command cat Display the contents of a file cd Change Directory chgrp Change group ownership chmod Change access permissions chown Change file owner and group chroot […]

Read More
Linux

List processes in a hierarchy

ps -e -o pid,args –forest List processes by % cpu usage ps -e -o pcpu,cpu,nice,state,cputime,args –sort pcpu | sed ‘/^ 0.0 /d’ List processes by mem usage ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS List info for particular process IDs ps -p 1,2

Read More
Scripting

Text manipulation using sed

Replace string1 with string2 sed ‘s/string1/string2/g’ Modify anystring1 to anystring2 sed ‘s/\(.*\)1/\12/g’ Remove comments and blank lines sed ‘/ *#/d; /^ *$/d’ Concatenate lines with trailing \ sed ‘:a; /\\$/N; s/\\\n//; ta’ Remove trailing spaces from lines sed ‘s/[ \t]*$//’ Escape shell metacharacters active within double quotes sed ‘s/\([\\`\\”$\\\\]\)/\\\1/g’ Print 1000th line sed -n ‘1000p;1000q’ […]

Read More