<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>My Online Guides, Tutorials Collection Blog &#187; Linux</title>
	<atom:link href="http://www.myguideblog.com/category/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://www.myguideblog.com</link>
	<description>My Online Guides, Tutorials Collection Blog</description>
	<lastBuildDate>Tue, 03 Mar 2009 03:24:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Command to check hardware</title>
		<link>http://www.myguideblog.com/linux/command-to-check-hardware-6367</link>
		<comments>http://www.myguideblog.com/linux/command-to-check-hardware-6367#comments</comments>
		<pubDate>Tue, 03 Mar 2009 03:21:24 +0000</pubDate>
		<dc:creator>KhaTu</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[linux command]]></category>

		<guid isPermaLink="false">http://www.myguideblog.com/?p=6367</guid>
		<description><![CDATA[Here are a few bash commands for finding out stuff.
Handy bash commands for finding out stuff in Linux:
 # Find CPU specifications
 cat /proc/cpuinfo
# Find running kernel version
 uname -r
# What compiler version do I have installed
 gcc -v
 gcc &#8211;version
# What is the running kernel and compiler installed
 cat /proc/version
# Find X server version
 [...]]]></description>
			<content:encoded><![CDATA[<p>Here are a few bash commands for finding out stuff.</p>
<p>Handy bash commands for finding out stuff in Linux:<br />
 # Find CPU specifications<br />
 cat /proc/cpuinfo</p>
<p># Find running kernel version<br />
 uname -r</p>
<p># What compiler version do I have installed<br />
 gcc -v<br />
 gcc &#8211;version</p>
<p># What is the running kernel and compiler installed<br />
 cat /proc/version</p>
<p># Find X server version<br />
 X -showconfig</p>
<p># What pci cards are installed and what irq/port is used<br />
 cat /proc/pci</p>
<p># What kernel modules are loaded<br />
 lsmod</p>
<p># Memory and swap information<br />
 cat /proc/meminfo<br />
 free<br />
 An article: <a href="http://www.home.linuxjournal.com/article.php?sid=2770" target="_blank">Tips for Optimizing Linux Memory</a></p>
<p># How are the hard drives partitioned<br />
 fdisk -l</p>
<p># How much free/used drive space<br />
 df -h</p>
<p># Show disk usage by current directory and all subdirectories<br />
 du | less</p>
<p># What takes up so much space on your box<br />
 # Run from the directory in question and the largest chunk shows up last<br />
 find $1 -type d | xargs du -sm | sort -g</p>
<p># What is the distribution<br />
 cat /etc/.product<br />
 cat /etc/.issue<br />
 cat /etc/issue<br />
 cat /etc/issue.net<br />
 sysinfo</p>
<p># For finding or locating files<br />
 find<br />
 locate<br />
 which<br />
 whereis</p>
<p># Use dmesg to view the kernel ring buffer (error messages)<br />
 dmesg | less</p>
<p># Watch error messages as they happen (sysklog needed)<br />
 as root, <strong>tail -f /var/log/messages</strong> (shows last 10 lines, use a number in front of f for more lines)</p>
<p># What processes are running<br />
 ps -A</p>
<p># Find a process by name<br />
 ps -ef | grep -i &lt;plain text&gt;<br />
 For example, XCDroast<br />
 ps -ef xcdroast</p>
<p># See current environment list, or pipe to file<br />
 env | more<br />
 env &gt; environmentvariablelist.txt</p>
<p># Show current userid and assigned groups<br />
 id</p>
<p># See all command aliases for the current user<br />
 alias</p>
<p># See rpms installed on current system<br />
 rpmquery &#8211;all | less<br />
 rpmquery &#8211;all &gt; &lt;filename&gt;<br />
 rpmquery &#8211;all | grep -i &lt;plaintext&gt;</p>
<p><a href="http://freshmeat.net/projects/autospec/?topic_id=147" target="_blank">Autospec</a> for tarballs<br />
 <a href="http://www.paganini.net/rpmtools/" target="_blank">RPM tools</a></p>
<p># What directory am I using<br />
 pwd</p>
<p># Get ls colors in less<br />
 ls &#8211;color=always | less -R</p>
<p>Look at <strong>man &lt;command&gt;</strong> or <strong>info &lt;command&gt;</strong> for the flags I used and for other options you can use for bash commands.</p>

	Tags: <a href="http://www.myguideblog.com/tag/command" title="command" rel="tag">command</a>, <a href="http://www.myguideblog.com/tag/hardware" title="hardware" rel="tag">hardware</a>, <a href="http://www.myguideblog.com/category/linux" title="Linux" rel="tag">Linux</a>, <a href="http://www.myguideblog.com/tag/linux-command" title="linux command" rel="tag">linux command</a><br /><script type="text/javascript"> google_ad_client = "pub-9646538075083871"; google_ad_channel ="3089257411"; google_ad_width = 468; google_ad_height = 15; google_ad_format = "468x15_0ads_al"; google_color_border = "FFFFFF"; google_color_bg = "ffffff"; google_color_link = "114269"; google_color_text = "114269"; google_color_url = "114269"; </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><br /><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.myguideblog.com/linux/15-examples-to-master-linux-command-line-history-10" title="15 Examples To Master Linux Command Line History (November 14, 2008)">15 Examples To Master Linux Command Line History</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.myguideblog.com/linux/command-to-check-hardware-6367/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Commands &#8211; MySQL Cheat sheet</title>
		<link>http://www.myguideblog.com/linux/mysql-commands-mysql-cheat-sheet-6333</link>
		<comments>http://www.myguideblog.com/linux/mysql-commands-mysql-cheat-sheet-6333#comments</comments>
		<pubDate>Mon, 16 Feb 2009 06:34:25 +0000</pubDate>
		<dc:creator>Tony Tran</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql cheat sheet]]></category>
		<category><![CDATA[mysql commands]]></category>

		<guid isPermaLink="false">http://www.myguideblog.com/?p=6333</guid>
		<description><![CDATA[This is a list of handy MySQL commands that I use time and time again. At the bottom are statements, clauses, and functions you can use in MySQL. Below that are PHP and Perl API functions you can use to interface with MySQL. To use those you will need to build PHP with MySQL functionality. [...]]]></description>
			<content:encoded><![CDATA[<p>This is a list of handy MySQL commands that I use time and time again. At the bottom are statements, clauses, and functions you can use in MySQL. Below that are PHP and Perl API functions you can use to interface with MySQL. To use those you will need to build PHP with MySQL functionality. To use MySQL with Perl you will need to use the Perl modules DBI and DBD::mysql.</p>
<p>Below when you see # it means from the unix shell. When you see mysql&gt; it means from a MySQL prompt after logging into MySQL.</p>
<h4>To login (from unix shell) use -h only if needed.</h4>
<p class="command"># [mysql dir]/bin/mysql -h hostname -u root -p</p>
<h4>Create a database on the sql server.</h4>
<p class="command">mysql&gt; create database [databasename];</p>
<h4>List all databases on the sql server.</h4>
<p class="command">mysql&gt; show databases;</p>
<h4>Switch to a database.</h4>
<p class="command">mysql&gt; use [db name];</p>
<h4>To see all the tables in the db.</h4>
<p class="command">mysql&gt; show tables;</p>
<h4>To see database&#8217;s field formats.</h4>
<p class="command">mysql&gt; describe [table name];</p>
<h4>To delete a db.</h4>
<p class="command">mysql&gt; drop database [database name];</p>
<h4>To delete a table.</h4>
<p class="command">mysql&gt; drop table [table name];</p>
<h4>Show all data in a table.</h4>
<p class="command">mysql&gt; SELECT * FROM [table name];</p>
<h4>Returns the columns and column information pertaining to the designated table.</h4>
<p class="command">mysql&gt; show columns from [table name];</p>
<h4>Show certain selected rows with the value &#8220;whatever&#8221;.</h4>
<p class="command">mysql&gt; SELECT * FROM [table name] WHERE [field name] = &#8220;whatever&#8221;;</p>
<h4>Show all records containing the name &#8220;Bob&#8221; AND the phone number &#8216;3444444&#8242;.</h4>
<p class="command">mysql&gt; SELECT * FROM [table name] WHERE name = &#8220;Bob&#8221; AND phone_number = &#8216;3444444&#8242;;</p>
<h4>Show all records not containing the name &#8220;Bob&#8221; AND the phone number &#8216;3444444&#8242; order by the phone_number field.</h4>
<p class="command">mysql&gt; SELECT * FROM [table name] WHERE name != &#8220;Bob&#8221; AND phone_number = &#8216;3444444&#8242; order by phone_number;</p>
<h4>Show all records starting with the letters &#8216;bob&#8217; AND the phone number &#8216;3444444&#8242;.</h4>
<p class="command">mysql&gt; SELECT * FROM [table name] WHERE name like &#8220;Bob%&#8221; AND phone_number = &#8216;3444444&#8242;;</p>
<h4>Show all records starting with the letters &#8216;bob&#8217; AND the phone number &#8216;3444444&#8242; limit to records 1 through 5.</h4>
<p class="command">mysql&gt; SELECT * FROM [table name] WHERE name like &#8220;Bob%&#8221; AND phone_number = &#8216;3444444&#8242; limit 1,5;</p>
<h4>Use a regular expression to find records. Use &#8220;REGEXP BINARY&#8221; to force case-sensitivity. This finds any record beginning with a.</h4>
<p class="command">mysql&gt; SELECT * FROM [table name] WHERE rec RLIKE &#8220;^a&#8221;;</p>
<h4>Show unique records.</h4>
<p class="command">mysql&gt; SELECT DISTINCT [column name] FROM [table name];</p>
<h4>Show selected records sorted in an ascending (asc) or descending (desc).</h4>
<p class="command">mysql&gt; SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;</p>
<h4>Return number of rows.</h4>
<p class="command">mysql&gt; SELECT COUNT(*) FROM [table name];</p>
<h4>Sum column.</h4>
<p class="command">mysql&gt; SELECT SUM(*) FROM [table name];</p>
<h4>Join tables on common columns.</h4>
<p class="command">mysql&gt; select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on  lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;</p>
<h4>Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs.</h4>
<p class="command"># mysql -u root -p<br />
 mysql&gt; use mysql;<br />
 mysql&gt; INSERT INTO user (Host,User,Password) VALUES(&#8216;%&#8217;,'username&#8217;,PASSWORD(&#8216;password&#8217;));<br />
 mysql&gt; flush privileges;</p>
<h4>Change a users password from unix shell.</h4>
<p class="command"># [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password &#8216;new-password&#8217;</p>
<h4>Change a users password from MySQL prompt. Login as root. Set the password. Update privs.</h4>
<p class="command"># mysql -u root -p<br />
 mysql&gt; SET PASSWORD FOR &#8216;user&#8217;@'hostname&#8217; = PASSWORD(&#8216;passwordhere&#8217;);<br />
 mysql&gt; flush privileges;</p>
<h4>Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables.  Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server.</h4>
<p class="command"># /etc/init.d/mysql stop<br />
 # mysqld_safe &#8211;skip-grant-tables &amp;<br />
 # mysql -u root<br />
 mysql&gt; use mysql;<br />
 mysql&gt; update user set password=PASSWORD(&#8220;newrootpassword&#8221;) where User=&#8217;root&#8217;;<br />
 mysql&gt; flush privileges;<br />
 mysql&gt; quit<br />
 # /etc/init.d/mysql stop<br />
 # /etc/init.d/mysql start</p>
<h4>Set a root password if there is on root password.</h4>
<p class="command"># mysqladmin -u root password newpassword</p>
<h4>Update a root password.</h4>
<p class="command"># mysqladmin -u root -p oldpassword newpassword</p>
<h4>Allow the user &#8220;bob&#8221; to connect to the server from localhost using the password &#8220;passwd&#8221;. Login as root. Switch to the MySQL db. Give privs. Update privs.</h4>
<p class="command"># mysql -u root -p<br />
 mysql&gt; use mysql;<br />
 mysql&gt; grant usage on *.* to bob@localhost identified by &#8216;passwd&#8217;;<br />
 mysql&gt; flush privileges;</p>
<h4>Give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs.</h4>
<p class="command"># mysql -u root -p<br />
 mysql&gt; use mysql;<br />
 mysql&gt; INSERT INTO user (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES  (&#8216;%&#8217;,'databasename&#8217;,'username&#8217;,'Y&#8217;,'Y&#8217;,'Y&#8217;,'Y&#8217;,'Y&#8217;,'N&#8217;);<br />
 mysql&gt; flush privileges; </p>
<p> or </p>
<p>mysql&gt; grant all privileges on databasename.* to username@localhost;<br />
 mysql&gt; flush privileges;</p>
<h4>To update info already in a table.</h4>
<p class="command">mysql&gt; UPDATE [table name] SET Select_priv = &#8216;Y&#8217;,Insert_priv = &#8216;Y&#8217;,Update_priv = &#8216;Y&#8217; where [field name] = &#8216;user&#8217;;</p>
<h4>Delete a row(s) from a table.</h4>
<p class="command">mysql&gt; DELETE from [table name] where [field name] = &#8216;whatever&#8217;;</p>
<h4>Update database permissions/privilages.</h4>
<p class="command">mysql&gt; flush privileges;</p>
<h4>Delete a column.</h4>
<p class="command">mysql&gt; alter table [table name] drop column [column name];</p>
<h4>Add a new column to db.</h4>
<p class="command">mysql&gt; alter table [table name] add column [new column name] varchar (20);</p>
<h4>Change column name.</h4>
<p class="command">mysql&gt; alter table [table name] change [old column name] [new column name] varchar (50);</p>
<h4>Make a unique column so you get no dupes.</h4>
<p class="command">mysql&gt; alter table [table name] add unique ([column name]);</p>
<h4>Make a column bigger.</h4>
<p class="command">mysql&gt; alter table [table name] modify [column name] VARCHAR(3);</p>
<h4>Delete unique from table.</h4>
<p class="command">mysql&gt; alter table [table name] drop index [colmn name];</p>
<h4>Load a CSV file into a table.</h4>
<p class="command">mysql&gt; LOAD DATA INFILE &#8216;/tmp/filename.csv&#8217; replace INTO TABLE [table name] FIELDS TERMINATED BY &#8216;,&#8217; LINES TERMINATED BY &#8216;\n&#8217; (field1,field2,field3);</p>
<h4>Dump all databases for backup. Backup file is sql commands to recreate all db&#8217;s.</h4>
<p class="command"># [mysql dir]/bin/mysqldump -u root -ppassword &#8211;opt &gt;/tmp/alldatabases.sql</p>
<h4>Dump one database for backup.</h4>
<p class="command"># [mysql dir]/bin/mysqldump -u username -ppassword &#8211;databases databasename &gt;/tmp/databasename.sql</p>
<h4>Dump a table from a database.</h4>
<p class="command"># [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename &gt; /tmp/databasename.tablename.sql</p>
<h4>Restore database (or database table) from backup.</h4>
<p class="command"># [mysql dir]/bin/mysql -u username -ppassword databasename &lt; /tmp/databasename.sql</p>
<h4>Create Table Example 1.</h4>
<p class="command">mysql&gt; CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255));</p>
<h4>Create Table Example 2.</h4>
<p class="command">mysql&gt; create table [table name] (personid int(50) not null auto_increment primary key,firstname varchar(35),middlename varchar(50),lastnamevarchar(50) default &#8216;bato&#8217;);</p>
<div style="text-align: center;">
<p><strong>MYSQL Statements and clauses</strong></p>
<pre>ALTER DATABASE

ALTER TABLE

ALTER VIEW

ANALYZE TABLE

BACKUP TABLE

CACHE INDEX

CHANGE MASTER TO

CHECK TABLE

CHECKSUM TABLE

COMMIT

CREATE DATABASE

CREATE INDEX

CREATE TABLE

CREATE VIEW

DELETE

DESCRIBE

DO

DROP DATABASE

DROP INDEX

DROP TABLE

DROP USER

DROP VIEW

EXPLAIN

FLUSH

GRANT

HANDLER

INSERT

JOIN

KILL

LOAD DATA FROM MASTER

LOAD DATA INFILE

LOAD INDEX INTO CACHE

LOAD TABLE...FROM MASTER

LOCK TABLES

OPTIMIZE TABLE

PURGE MASTER LOGS

RENAME TABLE

REPAIR TABLE

REPLACE

RESET

RESET MASTER

RESET SLAVE

RESTORE TABLE

REVOKE

ROLLBACK

ROLLBACK TO SAVEPOINT

SAVEPOINT

SELECT

SET

SET PASSWORD

SET SQL_LOG_BIN

SET TRANSACTION

SHOW BINLOG EVENTS

SHOW CHARACTER SET

SHOW COLLATION

SHOW COLUMNS

SHOW CREATE DATABASE

SHOW CREATE TABLE

SHOW CREATE VIEW

SHOW DATABASES

SHOW ENGINES

SHOW ERRORS

SHOW GRANTS

SHOW INDEX

SHOW INNODB STATUS

SHOW LOGS

SHOW MASTER LOGS

SHOW MASTER STATUS

SHOW PRIVILEGES

SHOW PROCESSLIST

SHOW SLAVE HOSTS

SHOW SLAVE STATUS

SHOW STATUS

SHOW TABLE STATUS

SHOW TABLES

SHOW VARIABLES

SHOW WARNINGS

START SLAVE

START TRANSACTION

STOP SLAVE

TRUNCATE TABLE

UNION

UNLOCK TABLES

USE
</pre>
<p><strong>String Functions</strong></p>
<pre>AES_DECRYPT

AES_ENCRYPT

ASCII

BIN

BINARY

BIT_LENGTH

CHAR

CHAR_LENGTH

CHARACTER_LENGTH

COMPRESS

CONCAT

CONCAT_WS

CONV

DECODE

DES_DECRYPT

DES_ENCRYPT

ELT

ENCODE

ENCRYPT

EXPORT_SET

FIELD

FIND_IN_SET

HEX

INET_ATON

INET_NTOA

INSERT

INSTR

LCASE

LEFT

LENGTH

LOAD_FILE

LOCATE

LOWER

LPAD

LTRIM

MAKE_SET

MATCH    AGAINST

MD5

MID

OCT

OCTET_LENGTH

OLD_PASSWORD

ORD

PASSWORD

POSITION

QUOTE

REPEAT

REPLACE

REVERSE

RIGHT

RPAD

RTRIM

SHA

SHA1

SOUNDEX

SPACE

STRCMP

SUBSTRING

SUBSTRING_INDEX

TRIM

UCASE

UNCOMPRESS

UNCOMPRESSED_LENGTH

UNHEX

UPPER
</pre>
<p><strong>Date and Time Functions</strong></p>
<pre>ADDDATE

ADDTIME

CONVERT_TZ

CURDATE

CURRENT_DATE

CURRENT_TIME

CURRENT_TIMESTAMP

CURTIME

DATE

DATE_ADD

DATE_FORMAT

DATE_SUB

DATEDIFF

DAY

DAYNAME

DAYOFMONTH

DAYOFWEEK

DAYOFYEAR

EXTRACT

FROM_DAYS

FROM_UNIXTIME

GET_FORMAT

HOUR

LAST_DAY

LOCALTIME

LOCALTIMESTAMP

MAKEDATE

MAKETIME

MICROSECOND

MINUTE

MONTH

MONTHNAME

NOW

PERIOD_ADD

PERIOD_DIFF

QUARTER

SEC_TO_TIME

SECOND

STR_TO_DATE

SUBDATE

SUBTIME

SYSDATE

TIME

TIMEDIFF

TIMESTAMP

TIMESTAMPDIFF

TIMESTAMPADD

TIME_FORMAT

TIME_TO_SEC

TO_DAYS

UNIX_TIMESTAMP

UTC_DATE

UTC_TIME

UTC_TIMESTAMP

WEEK

WEEKDAY

WEEKOFYEAR

YEAR

YEARWEEK
</pre>
<p><strong>Mathematical and Aggregate Functions</strong></p>
<pre>ABS

ACOS

ASIN

ATAN

ATAN2

AVG

BIT_AND

BIT_OR

BIT_XOR

CEIL

CEILING

COS

COT

COUNT

CRC32

DEGREES

EXP

FLOOR

FORMAT

GREATEST

GROUP_CONCAT

LEAST

LN

LOG

LOG2

LOG10

MAX

MIN

MOD

PI

POW

POWER

RADIANS

RAND

ROUND

SIGN

SIN

SQRT

STD

STDDEV

SUM

TAN

TRUNCATE

VARIANCE
</pre>
<p><strong>Flow Control Functions</strong></p>
<pre>CASE

IF

IFNULL

NULLIF
</pre>
<p><strong>Command-Line Utilities</strong></p>
<pre>comp_err

isamchk

make_binary_distribution

msql2mysql

my_print_defaults

myisamchk

myisamlog

myisampack

mysqlaccess

mysqladmin

mysqlbinlog

mysqlbug

mysqlcheck

mysqldump

mysqldumpslow

mysqlhotcopy

mysqlimport

mysqlshow

perror
</pre>
<p><strong>Perl API &#8211; using functions and methods built into the Perl DBI with MySQL</strong></p>
<pre>available_drivers

begin_work

bind_col

bind_columns

bind_param

bind_param_array

bind_param_inout

can

clone

column_info

commit

connect

connect_cached

data_sources

disconnect

do

dump_results

err

errstr

execute

execute_array

execute_for_fetch

fetch

fetchall_arrayref

fetchall_hashref

fetchrow_array

fetchrow_arrayref

fetchrow_hashref

finish

foreign_key_info

func

get_info

installed_versions

last_insert_id

looks_like_number

neat

neat_list

parse_dsn

parse_trace_flag

parse_trace_flags

ping

prepare

prepare_cached

primary_key

primary_key_info

quote

quote_identifier

rollback

rows

selectall_arrayref

selectall_hashref

selectcol_arrayref

selectrow_array

selectrow_arrayref

selectrow_hashref

set_err

state

table_info

table_info_all

tables

trace

trace_msg

type_info

type_info_all

Attributes for Handles
</pre>
<p><strong>PHP API &#8211; using functions built into PHP with MySQL</strong></p>
<pre>mysql_affected_rows

mysql_change_user

mysql_client_encoding

mysql_close

mysql_connect

mysql_create_db

mysql_data_seek

mysql_db_name

mysql_db_query

mysql_drop_db

mysql_errno

mysql_error

mysql_escape_string

mysql_fetch_array

mysql_fetch_assoc

mysql_fetch_field

mysql_fetch_lengths

mysql_fetch_object

mysql_fetch_row

mysql_field_flags

mysql_field_len

mysql_field_name

mysql_field_seek

mysql_field_table

mysql_field_type

mysql_free_result

mysql_get_client_info

mysql_get_host_info

mysql_get_proto_info

mysql_get_server_info

mysql_info

mysql_insert_id

mysql_list_dbs

mysql_list_fields

mysql_list_processes

mysql_list_tables

mysql_num_fields

mysql_num_rows

mysql_pconnect

mysql_ping

mysql_query

mysql_real_escape_string

mysql_result

mysql_select_db

mysql_stat

mysql_tablename

mysql_thread_id

mysql_unbuffered_query
</pre>
</div>

	Tags: <a href="http://www.myguideblog.com/tag/database" title="database" rel="tag">database</a>, <a href="http://www.myguideblog.com/category/linux" title="Linux" rel="tag">Linux</a>, <a href="http://www.myguideblog.com/tag/mysql" title="mysql" rel="tag">mysql</a>, <a href="http://www.myguideblog.com/tag/mysql-cheat-sheet" title="mysql cheat sheet" rel="tag">mysql cheat sheet</a>, <a href="http://www.myguideblog.com/tag/mysql-commands" title="mysql commands" rel="tag">mysql commands</a><br /><script type="text/javascript"> google_ad_client = "pub-9646538075083871"; google_ad_channel ="3089257411"; google_ad_width = 468; google_ad_height = 15; google_ad_format = "468x15_0ads_al"; google_color_border = "FFFFFF"; google_color_bg = "ffffff"; google_color_link = "114269"; google_color_text = "114269"; google_color_url = "114269"; </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><br /><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.myguideblog.com/linux/mysql-change-root-password-6328" title="MySQL Change root Password (February 16, 2009)">MySQL Change root Password</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.myguideblog.com/linux/mysql-commands-mysql-cheat-sheet-6333/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Change root Password</title>
		<link>http://www.myguideblog.com/linux/mysql-change-root-password-6328</link>
		<comments>http://www.myguideblog.com/linux/mysql-change-root-password-6328#comments</comments>
		<pubDate>Mon, 16 Feb 2009 06:27:54 +0000</pubDate>
		<dc:creator>Tony Tran</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[change root password]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql password]]></category>
		<category><![CDATA[mysql root password]]></category>
		<category><![CDATA[mysql root user]]></category>

		<guid isPermaLink="false">http://www.myguideblog.com/?p=6328</guid>
		<description><![CDATA[
MySQL Change root Password
by Vivek Gite

Q. How do I change MySQL root password under Linux, FreeBSD, OpenBSD and UNIX like operating system over ssh / telnet session?
A. Setting up mysql password is one of the essential tasks. root user is MySQL admin account. Please note that Linux / UNIX login root account for your operating [...]]]></description>
			<content:encoded><![CDATA[<div class="headline_area">
<h1 class="entry-title">MySQL Change root Password</h1>
<p class="headline_meta">by <span class="author vcard fn">Vivek Gite</span></p>
</div>
<p><span style="color: #ff0000;">Q</span>. How do I change MySQL root password under Linux, FreeBSD, OpenBSD and UNIX like operating system over ssh / telnet session?</p>
<p><span style="color: #009900;">A</span>. Setting up mysql password is one of the essential tasks. root user is MySQL admin account. Please note that Linux / UNIX login root account for your operating system and MySQL root are different. They are separate and nothing to do with each other (indeed some admin removes root account and setup admin as mysql super user).</p>
<h2>mysqladmin command to change root password</h2>
<p>If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:</p>
<pre>$ mysqladmin -u root password NEWPASSWORD</pre>
<p>However, if you want to change (or update) a root password, then you need to use following command</p>
<pre>$ mysqladmin -u root -p oldpassword newpass</pre>
<p>Enter password:</p>
<h2>Change MySQL password for other user</h2>
<p>To change a normal user password you need to type (let us assume you would like to change password for vivek):</p>
<pre>$ mysqladmin -u vivek -p oldpassword newpass</pre>
<h2>Changing MySQL root user password using mysql sql command</h2>
<p>This is another method. MySQL stores username and passwords in user table inside MySQL database. You can directly update password using the following method to update or change password for user vivek:</p>
<p>1) Login to mysql server, type following command at shell prompt:</p>
<pre>$ mysql -u root -p</pre>
<p>2) Use mysql database (type command at mysql&gt; prompt):</p>
<pre>mysql&gt; use mysql;</pre>
<p>3) Change password for user vivek:</p>
<pre>mysql&gt; update user set password=PASSWORD("NEWPASSWORD") where User='vivek';</pre>
<p>4) Reload privileges:</p>
<pre>mysql&gt; flush privileges;
mysql&gt; quit</pre>
<p>This method you need to use while using PHP or Perl scripting.</p>
<p><br class="spacer_" /></p>
<h1><strong>With Directadmin:</strong></h1>
<pre class="alt2" style="border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 500px; height: 130px; text-align: left;" dir="ltr">mysql --user=`grep "^user=" /usr/local/directadmin/conf/mysql.conf | cut -d= -f2` --password=`grep "^passwd=" /usr/local/directadmin/conf/mysql.conf | cut -d= -f2`
use mysql;
UPDATE user SET password=PASSWORD('<strong>newpass</strong>') WHERE user='root';
FLUSH PRIVILEGES;
quit</pre>

	Tags: <a href="http://www.myguideblog.com/tag/change-root-password" title="change root password" rel="tag">change root password</a>, <a href="http://www.myguideblog.com/category/linux" title="Linux" rel="tag">Linux</a>, <a href="http://www.myguideblog.com/tag/mysql" title="mysql" rel="tag">mysql</a>, <a href="http://www.myguideblog.com/tag/mysql-password" title="mysql password" rel="tag">mysql password</a>, <a href="http://www.myguideblog.com/tag/mysql-root-password" title="mysql root password" rel="tag">mysql root password</a>, <a href="http://www.myguideblog.com/tag/mysql-root-user" title="mysql root user" rel="tag">mysql root user</a><br /><script type="text/javascript"> google_ad_client = "pub-9646538075083871"; google_ad_channel ="3089257411"; google_ad_width = 468; google_ad_height = 15; google_ad_format = "468x15_0ads_al"; google_color_border = "FFFFFF"; google_color_bg = "ffffff"; google_color_link = "114269"; google_color_text = "114269"; google_color_url = "114269"; </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><br /><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.myguideblog.com/linux/mysql-commands-mysql-cheat-sheet-6333" title="MySQL Commands &#8211; MySQL Cheat sheet (February 16, 2009)">MySQL Commands &#8211; MySQL Cheat sheet</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.myguideblog.com/linux/mysql-change-root-password-6328/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UNIX Use and Security From The Ground Up</title>
		<link>http://www.myguideblog.com/linux/unix-use-and-security-from-the-ground-up-6222</link>
		<comments>http://www.myguideblog.com/linux/unix-use-and-security-from-the-ground-up-6222#comments</comments>
		<pubDate>Wed, 04 Feb 2009 05:47:08 +0000</pubDate>
		<dc:creator>KhaTu</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[ground up]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[unix security]]></category>
		<category><![CDATA[use unix]]></category>

		<guid isPermaLink="false">http://www.myguideblog.com/?p=6222</guid>
		<description><![CDATA[December 5, 1986.
INTRODUCTION
The Unix operating system is one of the most heavily used mainframe operating systems today. It runs on many different computers (Dec VAX&#8217;s, AT&#38;T&#8217;s 3bx series, PDP-11&#8217;s, and just about any other you can think of- including PC&#8217;s), and there are many different, but pretty much similar, versions of it. These Unix clones [...]]]></description>
			<content:encoded><![CDATA[<p>December 5, 1986.</p>
<p>INTRODUCTION</p>
<p>The Unix operating system is one of the most heavily used mainframe operating systems today. It runs on many different computers (Dec VAX&#8217;s, AT&amp;T&#8217;s 3bx series, PDP-11&#8217;s, and just about any other you can think of- including PC&#8217;s), and there are many different, but pretty much similar, versions of it. These Unix clones go by many different names- here are the most common: Xenix, Ultrix, Ros, IX/370 (for the IBM 370), PCIX (for the IBM PC), and Berkely (BSD) Unix. This file will concentrate on AT&amp;T System V Unix, probably the most heavily used version. (The next most heavily used is Berkely Unix.) This file will cover just about everything all but THE most advanced hacker will need to know about the Unix system, from the most rodent information to advanced hacking techniques. This is the second version of this file, and as I discover any errors or new tricks, I will update it. This file is, to the best of my knowledge, totally accurate, however, and the techniques in it will work just as described herein. Note, that these techniques will work on System V Unix. Not necessarily all, but most, should work on most other versions of Unix as well. Later, if this file is received well, and there is demand for another, I will release a file on yet more advanced techniques. If you wish to contact me, I can be reached several ways. First, on these boards: Shadow Spawn 219-659-1503 Private Sector 201-366-4431 (As prophet, not The Prophet&#8230;some rodent stole my name.) Ripco 312-528-5020 Stalag 13 215-657-8523 Phreak Klass 2600 806-799-0016 Or at this voice message system: 800-556-7001 Box 7023 I welcome any suggestions, corrections, or feedback of any kind. And lastly, thanks for taking the time to read this: THE USUAL DISCLAIMER: This file is for [of course] informational purposes only.  I don&#8217;t take responsibility for anything anyone does after reading this file.</p>
<p>IDENTIFYING UNIX SYSTEMS AND LOGGING IN</p>
<p>A Unix system can easily be identified by its prompts. When you first connect to a Unix system, you should receive the login prompt, which is usually &#8220;Login:&#8221; (Note, that the first character may or may not be capitalized.) On some systems, this prompt may be &#8220;;Login:&#8221; or &#8220;User:&#8221; (Again, the first letter may or may not be capitalized.) This may be preceded by a short message, (usually something like &#8220;WARNING!!! This system is for authorized users only!&#8221;), the name of the company that owns the system, or the uucp network name of the system. (The uucp facilities will be explained in detail later.) At this point, you should enter the user name and press return. (You should be in lowercase if your terminal supports it.) You should then receive the password prompt, &#8220;Password:&#8221; (And yet again, the &#8220;P&#8221; may or may not be capitalized.) At this point, you should enter your password and press return. If you have specified the correct username/password pair, you will then be admitted into the system. If you have entered a non-existant username or an incorrect password, you will receive the message &#8220;Login incorrect&#8221; and will be returned to the login prompt. There is little information given before login, and there is no way to find valid usernames from pre-login information. There are no &#8220;default&#8221; passwords in Unix. When the system is initially set up, none of the default accounts or any of the accounts created by the system operators has a password, until the system operator or the account owner set one for the account. Often, lazy system operators and unwary users do not bother to password many (and in some cases, all) of these accounts. To log in under an account that doesn&#8217;t have a password, you have only to enter the username at the login prompt. You may encounter some occasional error messages when attempting to log in under certain accounts. Here are some of the more common messages, and their causes: 1. &#8220;Unable to change directory to /usr/whatever&#8221;-This means that the account&#8217;s home directory, the directory which it is placed in upon logon, does not exist. On some systems, this may prevent you from logging under that account, and you will be returned to the login prompt. On other systems, you will simply be placed in the root directory. If this is the case, you will see the message &#8220;Changing directory to &#8216;/&#8217;&#8221;. 2. &#8220;No shell&#8221;-this means that the account&#8217;s shell, or command interpreter does not exist. On some systems, the account will not be allowed to log in, and you will be returned to the login prompt. On other systems, the account will be admitted into the system using a default shell, usually the Bourne shell. (The shell will be explained later.) If this is the case, you will see the message &#8220;Using /bin/sh&#8221;.</p>
<p>UNIX ACCOUNTS</p>
<p>There are two types of Unix accounts-user and superuser accounts. User accounts are the normal user accounts. These accounts have no privileges. Superuser accounts are the system operator accounts. These accounts have full privileges, and are not bound by the file and directory protections of other users. In Unix, there is no hierarchy of privileges-either an account has full privileges, or it has none. Unix usernames are up to 14 characters long, but usually are within the range of 1-8. The usernames can contain almost any characters, including control and special characters. (The accounts will usually not contain the characters @, control-d, control-j, or control-x, as these characters have special meanings to the Unix operating system.) The Unix system comes initially configured with quite a few default accounts, some of which are superuser and some of which are only user-level accounts. Here is a list of the default accounts which usually have superuser privileges: root (Always!) makefsys mountfsys umountfsys checkfsys The root account is always present on the system, and always has superuser capabilities. (Note: most Unix System V systems come initially set up with a security feature that prevents superuser accounts from logging in remotely. If you attempt to log in under a superuser account remotely on a system with this feature, you will receive the message &#8220;Not on console&#8221;, and will be refused admission to the operating system. This will NOT prevent you from using superuser accounts remotely-you simply have to log in under a user account and then switch over to a superuser account using the su utility, which will be described later.) Here is a list of the user-level default accounts: lp daemon trouble nuucp uucp bin rje adm sysadm sync The bin account, although it is only a user account, is particularly powerful, as it has ownership of many of the system&#8217;s important directories and files. Although these are the only default accounts on System V Unix, there are many other accounts which I have found to be common to many Unix systems. Here is a list of some of the accounts I have found on many Unix systems: batch admin user demo test field unix guest pub public standard games general student help gsa tty lpadmin Also try variations on the account names, such as rje1, rje2, user1, user2, etc. Also, try variations on people&#8217;s names and initials, such as doej, doe, john, johnd, jjd, etc. No matter what the format for the usernames, one thing is common to all systems-almost all of the usernames will begin with a lowercase letter. There is a good reason for this-when logging into the system, if the first character of the username you type in is in uppr-case, the system automatically assumes that your terminal does not support lower-case. It will then send all output to you in upper-case, with characters that are supposed to be upper-case preceded by a backslash (&#8220;\&#8221;, the Unix escape character), to differentiate them from the characters which are meant to be in lower-case. Unix *always* differentiates between the cases, so it is best to stay in lower-case while on the system. As mentioned before, there are no &#8220;default&#8221; passwords on Unix. When an account is created, it has no password, until the superuser or the account&#8217;s owner sets one for it. Unix passwords are a maximum of 11 characters. The password may contain any character, and the system distinguishes between upper and lower case characters. Many Unix systems implement a special security feature under which passwords must contain at least 2 non-alphanumeric characters (similar to Compuserve&#8217;s password protection). Yet another password security feature of Unix allows the superuser to set an expiration date on users&#8217; passwords.</p>

	Tags: <a href="http://www.myguideblog.com/tag/ground-up" title="ground up" rel="tag">ground up</a>, <a href="http://www.myguideblog.com/category/linux" title="Linux" rel="tag">Linux</a>, <a href="http://www.myguideblog.com/tag/unix" title="unix" rel="tag">unix</a>, <a href="http://www.myguideblog.com/tag/unix-security" title="unix security" rel="tag">unix security</a>, <a href="http://www.myguideblog.com/tag/use-unix" title="use unix" rel="tag">use unix</a><br /><script type="text/javascript"> google_ad_client = "pub-9646538075083871"; google_ad_channel ="3089257411"; google_ad_width = 468; google_ad_height = 15; google_ad_format = "468x15_0ads_al"; google_color_border = "FFFFFF"; google_color_bg = "ffffff"; google_color_link = "114269"; google_color_text = "114269"; google_color_url = "114269"; </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><br /><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.myguideblog.com/hacking-security/a-basic-unix-overview-5583" title="A Basic UNIX Overview (November 29, 2008)">A Basic UNIX Overview</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.myguideblog.com/linux/unix-use-and-security-from-the-ground-up-6222/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Secure SSH root access</title>
		<link>http://www.myguideblog.com/linux/secure-ssh-root-access-6109</link>
		<comments>http://www.myguideblog.com/linux/secure-ssh-root-access-6109#comments</comments>
		<pubDate>Mon, 02 Feb 2009 12:50:33 +0000</pubDate>
		<dc:creator>Tony Tran</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[protect ssh access]]></category>
		<category><![CDATA[root access]]></category>
		<category><![CDATA[secure ssh]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.myguideblog.com/linux/secure-ssh-root-access-6109</guid>
		<description><![CDATA[Secure SSH root access
Any web hosting provider would like to secure SSH root access on their dedicated web servers, to achieve this, my little contribution to you all. I hope this helps you all.


Add a user on the dedicated server
To begin, SSH into your server as root. Once you’re logged in, you should see a [...]]]></description>
			<content:encoded><![CDATA[<h2>Secure SSH root access</h2>
<p>Any web hosting provider would like to secure SSH root access on their dedicated web servers, to achieve this, my little contribution to you all. I hope this helps you all.</p>
<p><a href="http://www.supportfacility.com/hosting-support-facility-starter-plan.php"><br />
</a></p>
<p><span style="text-decoration: underline;"><strong>Add a user on the dedicated server</strong></span></p>
<p>To begin, SSH into your server as root. Once you’re logged in, you should see a shell prompt similar to:</p>
<pre>root@server[~]#</pre>
<p>The command to add a user is as below. I will be using the username as “support”.</p>
<pre>root@server[~]# /usr/sbin/adduser support</pre>
<p>Once the user is added you can verify by using the below command:</p>
<pre>root@server[~]# cat /etc/passwd | grep support</pre>
<p><span style="text-decoration: underline;"><strong>Set a password for the user (support)</strong></span></p>
<p>Use the below command to set password for the user “support”:</p>
<pre>root@server[~]# passwd support</pre>
<p>Note: Make sure you pick a secure password which will consist between 6-8 characters, and will contain letters, numbers, and punctuation marks.</p>
<p>To make sure this user account that you have created works, open another SSH window and proceed to log in with the user “support”. Once you’ve successfully verified that this account works, you may exit the session.</p>
<p><span style="text-decoration: underline;"><strong>Verifying su’s command permissions, and ownership </strong></span></p>
<p>Verifying “su” command is owned by root and the wheel group is suggested. At the same time check the permissions are set correctly.<br />
This can be checked by the below command:</p>
<pre>root@server [~]# ls -la /bin/su</pre>
<p>The output should be:</p>
<pre>-rwsr-x---  1 root wheel 61168 Nov 18 07:17 /bin/su*</pre>
<pre>If the output is as above you can skip this below command:</pre>
<p>—<br />
Su user ownership, permission can be set by the below command:<br />
root@server [~]# chmod 4750 /bin/su<br />
root@server [~]# chown root:wheel /bin/su<br />
root@server [~]# chmod +s /bin/su<br />
—</p>
<p><span style="text-decoration: underline;"><strong>Now, add the user to the wheel group </strong></span></p>
<p>We will have to add our new user “support” to the wheel group in order to allow it to gain root access, with *NO* root privileges. That means that this user will be able to log into the server, but won’t be able to perform any root tasks until the user switches to the root user.</p>
<p>In SSH you have to type the below command:</p>
<pre>root@server[~]# /usr/sbin/usermod –G wheel support</pre>
<p>Before proceeding, re-login to your server using the “support” account. At the SSH prompt, type “su” followed by the Enter key, and then enter in the root password. If you were successful, you should be at a root prompt:</p>
<p>root@server [~]#</p>
<p>To confirm that you are root, at the SSH prompt type the command <strong>whoami </strong>, which should display your root account.</p>
<p><span style="text-decoration: underline;"><strong>Editing the sshd_config file, and restarting SSH daemon </strong></span></p>
<p>Now we have to disable direct root access to your dedicated web server. Use the below command:</p>
<p><strong>nano /etc/ssh/sshd_config </strong></p>
<p>Scroll down until you see the following come across the screen:</p>
<pre>#LoginGraceTime 600
#PermitRootLogin yes
#StrictModes yes</pre>
<p>To disable SSH root login, remove the hash symbol <strong>(#)</strong> before PermitRootLogin , and change the “<strong>yes</strong>” next to PermitRootLogin to “<strong>no</strong>” so now it looks like:</p>
<pre>#LoginGraceTime 120
PermitRootLogin no
#StrictModes yes</pre>
<p>Note: If you see the value of LoginGraceTime different from my value of 120, you do not need to worry as it does not affect the functionality.</p>
<pre>Restarting SSH daemon</pre>
<p>Finally, to make the changes take effect, you have to restart SSH by running the following command (as root):</p>
<pre>root@server [~]# service sshd restart</pre>
<p>Best of luck!</p>

	Tags: <a href="http://www.myguideblog.com/category/linux" title="Linux" rel="tag">Linux</a>, <a href="http://www.myguideblog.com/tag/protect-ssh-access" title="protect ssh access" rel="tag">protect ssh access</a>, <a href="http://www.myguideblog.com/tag/root-access" title="root access" rel="tag">root access</a>, <a href="http://www.myguideblog.com/tag/secure-ssh" title="secure ssh" rel="tag">secure ssh</a>, <a href="http://www.myguideblog.com/tag/ssh" title="ssh" rel="tag">ssh</a><br /><script type="text/javascript"> google_ad_client = "pub-9646538075083871"; google_ad_channel ="3089257411"; google_ad_width = 468; google_ad_height = 15; google_ad_format = "468x15_0ads_al"; google_color_border = "FFFFFF"; google_color_bg = "ffffff"; google_color_link = "114269"; google_color_text = "114269"; google_color_url = "114269"; </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><br /><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.myguideblog.com/linux/secure-ssh-root-access-6109/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Find and Check Number of Connections to a Server</title>
		<link>http://www.myguideblog.com/linux/how-to-find-and-check-number-of-connections-to-a-server-6104</link>
		<comments>http://www.myguideblog.com/linux/how-to-find-and-check-number-of-connections-to-a-server-6104#comments</comments>
		<pubDate>Wed, 21 Jan 2009 07:17:05 +0000</pubDate>
		<dc:creator>Tony Tran</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[check connections]]></category>
		<category><![CDATA[ddos]]></category>
		<category><![CDATA[flood]]></category>
		<category><![CDATA[netstat]]></category>

		<guid isPermaLink="false">http://www.myguideblog.com/?p=6104</guid>
		<description><![CDATA[Whenever a client connects to a server via network, a connection is established and opened on the system. On a busy high load server, the number of connections connected to the server can be run into large amount till hundreds if not thousands. Find out and get a list of connections on the server by [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever a client connects to a server via network, a connection is established and opened on the system. On a busy high load server, the number of connections connected to the server can be run into large amount till hundreds if not thousands. Find out and get a list of connections on the server by each node, client or IP address is useful for system scaling planning, and in most cases, detect and determine whether a web server is under DoS or DDoS attack (Distributed Denial of Service), where an IP sends large amount of connections to the server. To check connection numbers on the server, administrators and webmasters can make use of netstat command.</p>
<p>Below is some of the example a typically use command syntax for ‘netstat’ to check and show the number of connections a server has. Users can also use ‘man netstat’ command to get detailed netstat help and manual where there are lots of configurable options and flags to get meaningful lists and results.</p>
<p><span style="color: #ff0000;"><code>netstat -na</code></span><br />
Display all active Internet connections to the servers and only established connections are included.</p>
<p><span style="color: #ff0000;"><code>netstat -an | grep :80 | sort</code></span></p>
<p>Show only active Internet connections to the server at port 80 and sort the results. Useful in detecting single flood by allowing users to recognize many connections coming from one IP.</p>
<p><span style="color: #ff0000;"><code>netstat -n -p|grep SYN_REC | wc -l</code></span><br />
Let users know how many active SYNC_REC are occurring and happening on the server. The number should be pretty low, preferably less than 5. On DoS attack incident or mail bombed, the number can jump to twins. However, the value always depends on system, so a high value may be average in another server.</p>
<p><span style="color: #ff0000;"><code>netstat -n -p | grep SYN_REC | sort -u</code></span><br />
List out the all IP addresses involved instead of just count.</p>
<p><span style="color: #ff0000;"><code>netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'</code></span><br />
List all the unique IP addresses of the node that are sending SYN_REC connection status.</p>
<p><span style="color: #ff0000;"><code>netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n</code></span><br />
Use netstat command to calculate and count the number of connections each IP address makes to the server.</p>
<p><span style="color: #ff0000;"><code>netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n</code></span><br />
List count of number of connections the IPs are connected to the server using TCP or UDP protocol.</p>
<p><span style="color: #ff0000;"><code>netstat -ntu | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr</code></span><br />
Check on ESTABLISHED connections instead of all connections, and displays the connections count for each IP.</p>
<p><span style="color: #ff0000;"><code>netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1</code></span><br />
Show and list IP address and its connection count that connect to port 80 on the server. Port 80 is used mainly by HTTP web page request.</p>

	Tags: <a href="http://www.myguideblog.com/tag/check-connections" title="check connections" rel="tag">check connections</a>, <a href="http://www.myguideblog.com/tag/ddos" title="ddos" rel="tag">ddos</a>, <a href="http://www.myguideblog.com/tag/flood" title="flood" rel="tag">flood</a>, <a href="http://www.myguideblog.com/category/linux" title="Linux" rel="tag">Linux</a>, <a href="http://www.myguideblog.com/tag/netstat" title="netstat" rel="tag">netstat</a><br /><script type="text/javascript"> google_ad_client = "pub-9646538075083871"; google_ad_channel ="3089257411"; google_ad_width = 468; google_ad_height = 15; google_ad_format = "468x15_0ads_al"; google_color_border = "FFFFFF"; google_color_bg = "ffffff"; google_color_link = "114269"; google_color_text = "114269"; google_color_url = "114269"; </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><br /><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.myguideblog.com/linux/how-to-find-and-check-number-of-connections-to-a-server-6104/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exim cheatsheet</title>
		<link>http://www.myguideblog.com/linux/exim-cheatsheet-5733</link>
		<comments>http://www.myguideblog.com/linux/exim-cheatsheet-5733#comments</comments>
		<pubDate>Tue, 02 Dec 2008 06:41:40 +0000</pubDate>
		<dc:creator>Tony Tran</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[exim]]></category>
		<category><![CDATA[exim cheat]]></category>
		<category><![CDATA[exim cheatsheet]]></category>
		<category><![CDATA[exim tutorials]]></category>

		<guid isPermaLink="false">http://www.myguideblog.com/?p=5733</guid>
		<description><![CDATA[Here are some useful things to know for managing an Exim 4 server. This assumes a prior working knowledge of SMTP, MTAs, and a UNIX shell prompt.
Message-IDs and spool files
The message-IDs that Exim uses to refer to messages in its queue are mixed-case alpha-numeric, and take the form of: XXXXXX-YYYYYY-ZZ. Most commands related to managing [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some useful things to know for managing an Exim 4 server. This assumes a prior working knowledge of SMTP, MTAs, and a UNIX shell prompt.</p>
<h3>Message-IDs and spool files</h3>
<p>The message-IDs that Exim uses to refer to messages in its queue are mixed-case alpha-numeric, and take the form of: XXXXXX-YYYYYY-ZZ. Most commands related to managing the queue and logging use these message-ids.</p>
<p>There are three &#8212; count &#8216;em, THREE &#8212; files for each message in the spool directory. If you&#8217;re dealing with these files by hand, instead of using the appropriate exim commands as detailed below, make sure you get them all, and don&#8217;t leave Exim with remnants of messages in the queue. I used to mess directly with these files when I first started running Exim machines, but thanks to the utilities described below, I haven&#8217;t needed to do that in many months.</p>
<p>Files in /var/spool/exim/msglog contain logging information for each message and are named the same as the message-id.</p>
<p>Files in /var/spool/exim/input are named after the message-id, plus a suffix denoting whether it is the envelope header (-H) or message data (-D).</p>
<p>These directories may contain further hashed subdirectories to deal with larger mail queues, so don&#8217;t expect everything to always appear directly in the top /var/spool/exim/input or /var/spool/exim/msglog directories; any searches or greps will need to be recursive. See if there is a proper way to do what you&#8217;re doing before working directly on the spool files.</p>
<h3>Basic information</h3>
<p>Print a count of the messages in the queue:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -bpc</pre>
<p>Print a listing of the messages in the queue (time queued, size, message-id, sender, recipient):</p>
<pre class="shell"><strong>root@localhost#</strong> exim -bp</pre>
<p>Print a summary of messages in the queue (count, volume, oldest, newest, domain, and totals):</p>
<pre class="shell"><strong>root@localhost#</strong> exim -bp | exiqsumm</pre>
<p>Print what Exim is doing right now:</p>
<pre class="shell"><strong>root@localhost#</strong> exiwhat</pre>
<p>Test how exim will route a given address:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -bt alias@localdomain.com
user@thishost.com
    &lt;-- alias@localdomain.com
  router = localuser, transport = local_delivery
<strong>root@localhost#</strong> exim -bt user@thishost.com
user@thishost.com
  router = localuser, transport = local_delivery
<strong>root@localhost#</strong> exim -bt user@remotehost.com
  router = lookuphost, transport = remote_smtp
  host mail.remotehost.com [1.2.3.4] MX=0</pre>
<p>Run a pretend SMTP transaction from the command line, as if it were coming from the given IP address. This will display Exim&#8217;s checks, ACLs, and filters as they are applied. The message will NOT actually be delivered.</p>
<pre class="shell"><strong>root@localhost#</strong> exim -bh 192.168.11.22</pre>
<p>Display all of Exim&#8217;s configuration settings:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -bP</pre>
<h3>Searching the queue with exiqgrep</h3>
<p>Exim includes a utility that is quite nice for grepping through the queue, called exiqgrep.  <a href="http://www.exim.org/exim-html-4.50/doc/html/spec_49.html#IX2895"> Learn it. Know it. Live it.</a> If you&#8217;re not using this, and if you&#8217;re not familiar with the various flags it uses, you&#8217;re probably doing things the hard way, like piping `exim -bp` into awk, grep, cut, or `wc -l`. Don&#8217;t make life harder than it already is.</p>
<p>First, various flags that control what messages are matched. These can be combined to come up with a very particular search.</p>
<p>Use -f to search the queue for messages from a specific sender:</p>
<pre class="shell"><strong>root@localhost#</strong> exiqgrep -f [luser]@domain</pre>
<p>Use -r to search the queue for messages for a specific recipient/domain:</p>
<pre class="shell"><strong>root@localhost#</strong> exiqgrep -r [luser]@domain</pre>
<p>Use -o to print messages older than the specified number of seconds. For example, messages older than 1 day:</p>
<pre class="shell"><strong>root@localhost#</strong> exiqgrep -o 86400 [...]</pre>
<p>Use -y to print messages that are younger than the specified number of seconds. For example, messages less than an hour old:</p>
<pre class="shell"><strong>root@localhost#</strong> exiqgrep -y 3600 [...]</pre>
<p>Use -s to match the size of a message with a regex. For example, 700-799 bytes:</p>
<pre class="shell"><strong>root@localhost#</strong> exiqgrep -s '^7..$' [...]</pre>
<p>Use -z to match only frozen messages, or -x to match only unfrozen messages.</p>
<p>There are also a few flags that control the display of the output.</p>
<p>Use -i to print just the message-id as a result of one of the above two searches:</p>
<pre class="shell"><strong>root@localhost#</strong> exiqgrep -i [ -r | -f ] ...</pre>
<p>Use -c to print a count of messages matching one of the above searches:</p>
<pre class="shell"><strong>root@localhost#</strong> exiqgrep -c ...</pre>
<p>Print just the message-id of the entire queue:</p>
<pre class="shell"><strong>root@localhost#</strong> exiqgrep -i</pre>
<h3>Managing the queue</h3>
<p>The main exim binary (/usr/sbin/exim) is used with various flags to make things happen to messages in the queue. Most of these require one or more message-IDs to be specified in the command line, which is where `exiqgrep -i` as described above really comes in handy.</p>
<p>Start a queue run:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -q -v</pre>
<p>Start a queue run for just local deliveries:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -ql -v</pre>
<p>Remove a message from the queue:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -Mrm &lt;message-id&gt; [ &lt;message-id&gt; ... ]</pre>
<p>Freeze a message:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -Mf &lt;message-id&gt; [ &lt;message-id&gt; ... ]</pre>
<p>Thaw a message:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -Mt &lt;message-id&gt; [ &lt;message-id&gt; ... ]</pre>
<p>Deliver a message, whether it&#8217;s frozen or not, whether the retry time has been reached or not:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -M &lt;message-id&gt; [ &lt;message-id&gt; ... ]</pre>
<p>Deliver a message, but only if the retry time has been reached:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -Mc &lt;message-id&gt; [ &lt;message-id&gt; ... ]</pre>
<p>Force a message to fail and bounce as &#8220;cancelled by administrator&#8221;:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -Mg &lt;message-id&gt; [ &lt;message-id&gt; ... ]</pre>
<h2>To remove all messages from the queue, enter:</h2>
<p><code># exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bash</code></p>
<pre class="shell"></pre>
<p>Remove all frozen messages:</p>
<pre class="shell"><strong>root@localhost#</strong> exiqgrep -z -i | xargs exim -Mrm</pre>
<p>Remove all messages older than five days (86400 * 5 = 432000 seconds):</p>
<pre class="shell"><strong>root@localhost#</strong> exiqgrep -o 432000 -i | xargs exim -Mrm</pre>
<p>Freeze all queued mail from a given sender:</p>
<pre class="shell"><strong>root@localhost#</strong> exiqgrep -i -f luser@example.tld | xargs exim -Mf</pre>
<p>View a message&#8217;s headers:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -Mvh &lt;message-id&gt;</pre>
<p>View a message&#8217;s body:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -Mvb &lt;message-id&gt;</pre>
<p>View a message&#8217;s logs:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -Mvl &lt;message-id&gt;</pre>
<p>Add a recipient to a message:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -Mar &lt;message-id&gt; &lt;address&gt; [ &lt;address&gt; ... ]</pre>
<p>Edit the sender of a message:</p>
<pre class="shell"><strong>root@localhost#</strong> exim -Mes &lt;message-id&gt; &lt;address&gt;</pre>
<h3>Access control</h3>
<p>Exim allows you to apply <a href="http://www.exim.org/exim-html-4.50/doc/html/spec_39.html">access control lists</a> at various points of the SMTP transaction by specifying an ACL to use and defining its conditions in exim.conf. You could start with the HELO string.</p>
<pre class="code"># Specify the ACL to use after HELO
acl_smtp_helo = check_helo

# Conditions for the check_helo ACL:
check_helo:

    deny message = Gave HELO/EHLO as "friend"
    log_message = HELO/EHLO friend
    condition = ${if eq {$sender_helo_name}{friend} {yes}{no}}

    deny message = Gave HELO/EHLO as our IP address
    log_message = HELO/EHLO our IP address
    condition = ${if eq {$sender_helo_name}{$interface_address} {yes}{no}}

    accept</pre>
<p>NOTE: Pursue HELO checking at your own peril.  The HELO is fairly unimportant in the grand scheme of SMTP these days, so don&#8217;t put too much faith in whatever it contains.  Some spam might seem to use a telltale HELO string, but you might be surprised at how many legitimate messages start off with a questionable HELO as well.  Anyway, it&#8217;s just as easy for a spammer to send a proper HELO than it is to send HELO im.a.spammer, so consider yourself lucky if you&#8217;re able to stop much spam this way.</p>
<p>Next, you can perform a check on the sender address or remote host. This shows how to do that after the RCPT TO command; if you reject here, as opposed to rejecting after the MAIL FROM, you&#8217;ll have better data to log, such as who the message was intended for.</p>
<pre class="code"># Specify the ACL to use after RCPT TO
acl_smtp_rcpt = check_recipient

# Conditions for the check_recipient ACL
check_recipient:

    # [...]

    drop hosts = /etc/exim_reject_hosts
    drop senders = /etc/exim_reject_senders

    # [ Probably a whole lot more... ]</pre>
<p>This example uses two plain text files as blacklists. Add appropriate entries to these files &#8211; hostnames/IP addresses to /etc/exim_reject_hosts, addresses to /etc/exim_reject_senders, one entry per line.</p>
<p>It is also possible to perform <a href="http://www.exim.org/exim-html-4.50/doc/html/spec_40.html">content scanning</a> using a regex against the body of a message, though obviously this can cause Exim to use more CPU than it otherwise would need to, especially on large messages.</p>
<pre class="code"># Specify the ACL to use after DATA
acl_smtp_data = check_message

# Conditions for the check_messages ACL
check_message:

    deny message = "Sorry, Charlie: $regex_match_string"
    regex = ^Subject:: .*Lower your self-esteem by becoming a sysadmin

    accept</pre>
<h3>Fix SMTP-Auth for Pine</h3>
<p>If pine can&#8217;t use SMTP authentication on an Exim host and just returns an &#8220;unable to authenticate&#8221; message without even asking for a password, add the following line to exim.conf:</p>
<pre class="code">  begin authenticators

  fixed_plain:
  driver = plaintext
  public_name = PLAIN
  server_condition = "${perl{checkuserpass}{$1}{$2}{$3}}"
  server_set_id = $2
&gt;<strong>  server_prompts = :</strong></pre>
<p>This was a problem on CPanel Exim builds awhile ago, but they seem to have added this line to their current stock configuration.</p>
<h3>Log the subject line</h3>
<p>This is one of the most useful configuration tweaks I&#8217;ve ever found for Exim. Add this to exim.conf, and you can log the subject lines of messages that pass through your server. This is great for troubleshooting, and for getting a very rough idea of what messages may be spam.</p>
<pre class="code">log_selector = +subject</pre>
<p><a href="http://www.exim.org/exim-html-4.50/doc/html/spec_48.html#SECT48.15">Reducing or increasing what is logged</a>.</p>
<h3>Disable identd lookups</h3>
<p>Frankly, I don&#8217;t think <a href="http://www.ietf.org/rfc/rfc1413.txt">identd</a> has been useful for a long time, if ever.  Identd relies on the connecting host to confirm the identity (system UID) of the remote user who owns the process that is making the network connection.  This may be of some use in the world of shell accounts and IRC users, but it really has no place on a high-volume SMTP server, where the UID is often simply &#8220;mail&#8221; or whatever the remote MTA runs as, which is useless to know. It&#8217;s overhead, and results in nothing but delays while the identd query is refused or times out. You can stop your Exim server from making these queries by setting the timeout to zero seconds in exim.conf:</p>
<pre class="code">rfc1413_query_timeout = 0s</pre>
<h3>Disable Attachment Blocking</h3>
<p>To disable the executable-attachment blocking that many Cpanel servers do by default but don&#8217;t provide any controls for on a per-domain basis, add the following block to the beginning of the /etc/antivirus.exim file:</p>
<pre class="code">if $header_to: matches "example\.com|example2\.com"
then
  finish
endif</pre>
<p>It is probably possible to use a separate file to list these domains, but I haven&#8217;t had to do this enough times to warrant setting such a thing up.</p>
<h3>Searching the logs with exigrep</h3>
<p>The <a href="http://www.exim.org/exim-html-4.50/doc/html/spec_49.html#IX2911">exigrep</a> utility (not to be confused with exiqgrep) is used to search an exim log for a string or pattern. It will print all log entries with the same internal message-id as those that matched the pattern, which is very handy since any message will take up at least three lines in the log. exigrep will search the entire content of a log entry, not just particular fields.</p>
<p>One can search for messages sent from a particular IP address:</p>
<pre class="shell"><strong>root@localhost#</strong> exigrep '&lt;= .* \[12.34.56.78\] ' /path/to/exim_log</pre>
<p>Search for messages sent to a particular IP address:</p>
<pre class="shell"><strong>root@localhost#</strong> exigrep '=&gt; .* \[12.34.56.78\]' /path/to/exim_log</pre>
<p>This example searches for outgoing messages, which have the &#8220;=&gt;&#8221; symbol, sent to &#8220;user@domain.tld&#8221;.  The pipe to grep for the &#8220;&lt;=&#8221; symbol will match only the lines with information on the sender &#8211; the From address, the sender&#8217;s IP address, the message size, the message ID, and the subject line if you have enabled logging the subject. The purpose of doing such a search is that the desired information is not on the same log line as the string being searched for.</p>
<pre class="shell"><strong>root@localhost#</strong> exigrep '=&gt; .*user@domain.tld' /path/to/exim_log | fgrep '&lt;='</pre>
<p>Generate and display Exim stats from a logfile:</p>
<pre class="shell"><strong>root@localhost#</strong> eximstats /path/to/exim_mainlog</pre>
<p>Same as above, with less verbose output:</p>
<pre class="shell"><strong>root@localhost#</strong> eximstats -ne -nr -nt /path/to/exim_mainlog</pre>
<p>Same as above, for one particular day:</p>
<pre class="shell"><strong>root@localhost#</strong> fgrep YYYY-MM-DD /path/to/exim_mainlog | eximstats</pre>
<h3>Bonus!</h3>
<p>To delete all queued messages containing a certain string in the body:</p>
<pre class="shell"><strong>root@localhost#</strong> grep -lr 'a certain string' /var/spool/exim/input/ | \
                sed -e 's/^.*\/\([a-zA-Z0-9-]*\)-[DH]$/\1/g' | xargs exim -Mrm</pre>
<p>Note that the above only delves into /var/spool/exim in order to grep for queue files with the given string, and that&#8217;s just because exiqgrep doesn&#8217;t have a feature to grep the actual bodies of messages. If you are deleting these files directly, YOU ARE DOING IT WRONG! Use the appropriate exim command to properly deal with the queue.</p>
<p>If you have to feed many, many message-ids (such as the output of an `exiqgrep -i` command that returns a lot of matches) to an exim command, you may exhaust the limit of your shell&#8217;s command line arguments.  In that case, pipe the listing of message-ids into xargs to run only a limited number of them at once. For example, to remove thousands of messages sent from joe@example.com:</p>
<pre class="shell"><strong>root@localhost#</strong> exiqgrep -i -f '&lt;joe@example.com&gt;' | xargs exim -Mrm</pre>
<h3>Speaking of &#8220;DOING IT WRONG&#8221; &#8212; Attention, CPanel forum readers</h3>
<p>I get a number of hits to this page from a link in <a href="http://forums.cpanel.net/showthread.php?t=54858">this post</a> at the CPanel forums. The question is:</p>
<blockquote><p>Due to spamming, spoofing from fields, etc., etc., etc., I am finding it necessary to spend more time to clear the exim queue from time to time. [...] what command would I use to delete the queue</p></blockquote>
<p>The answer is: Just turn exim off, because your customers are better off knowing that email simply isn&#8217;t running on your server, than having their queued messages deleted without notice.</p>
<p>Or, figure out what is happening. The examples given in that post pay no regard to the legitimacy of any message, they simply delete everything, making the presumption that if a message is in the queue, it&#8217;s junk. That is total fallacy.  There are a number of reasons legitimate mail can end up in the queue.  Maybe your backups or CPanel&#8217;s &#8220;upcp&#8221; process are running, and your load average is high &#8212; exim goes into a queue-only mode at a certain threshold, where it stops trying to deliver messages as they come in and just queues them until the load goes back down. Or, maybe it&#8217;s an outgoing message, and the DNS lookup failed, or the connection to the domain&#8217;s MX failed, or maybe the remote MX is busy or greylisting you with a 4xx deferral. These are all temporary failures, not permanent ones, and the whole point of having temporary failures in SMTP and a mail queue in your MTA is to be able to try again after awhile.</p>
<p>Exim already purges messages from the queue after the period of time specified in exim.conf. If you have this value set appropriately, there is absolutely no point in removing everything from your queue every day with a cron job. <strong>You will lose legitimate mail, and the sender and recipient will never know if or why it happened.</strong> Do not do this!</p>
<p>If you regularly have a large number of messages in your queue, find out why they are there. If they are outbound messages, see who is sending them, where they&#8217;re addressed to, and why they aren&#8217;t getting there.  If they are inbound messages, find out why they aren&#8217;t getting delivered to your user&#8217;s account. If you need to delete some, use exiqgrep to pick out just the ones that should be deleted.</p>
<h3>Reload the configuration</h3>
<p>After making changes to exim.conf, you need to give the main exim pid a SIGHUP to re-exec it and have the configuration re-read. Sure, you could stop and start the service, but that&#8217;s overkill and causes a few seconds of unnecessary downtime. Just do this:</p>
<pre class="shell"><strong>root@localhost#</strong> kill -HUP `cat /var/spool/exim/exim-daemon.pid`</pre>
<p>You should then see something resembling the following in exim_mainlog:</p>
<pre class="code">pid 1079: SIGHUP received: re-exec daemon
exim 4.52 daemon started: pid=1079, -q1h, listening for SMTP on port 25 (IPv4)</pre>
<h3>Read The Fucking Manual</h3>
<p><a href="http://www.exim.org/">The Exim Home Page</a></p>
<p><a href="http://www.exim.org/docs.html">Documentation For Exim</a></p>
<p><a href="http://www.exim.org/exim-html-4.50/doc/html/spec.html">The Exim Specification &#8211; Version 4.5x</a></p>
<p><a href="http://www.exim.org/exim-html-4.50/doc/html/spec_5.html#IX199">Exim command line arguments</a></p>
<h3>Any questions?</h3>
<p>Well, don&#8217;t ask me! I&#8217;m one guy, with just enough time and Exim skills to keep my own stuff running okay.  There are several (perhaps even dozens) of people on the Internet who know way more than me, and who are willing to help out random strangers. Check into the <a href="http://lists.exim.org/lurker/list/exim-users.html">Exim users mailing list</a>, or one of the many web-based gateways to that list. And good luck.</p>

	Tags: <a href="http://www.myguideblog.com/tag/exim" title="exim" rel="tag">exim</a>, <a href="http://www.myguideblog.com/tag/exim-cheat" title="exim cheat" rel="tag">exim cheat</a>, <a href="http://www.myguideblog.com/tag/exim-cheatsheet" title="exim cheatsheet" rel="tag">exim cheatsheet</a>, <a href="http://www.myguideblog.com/tag/exim-tutorials" title="exim tutorials" rel="tag">exim tutorials</a>, <a href="http://www.myguideblog.com/category/linux" title="Linux" rel="tag">Linux</a><br /><script type="text/javascript"> google_ad_client = "pub-9646538075083871"; google_ad_channel ="3089257411"; google_ad_width = 468; google_ad_height = 15; google_ad_format = "468x15_0ads_al"; google_color_border = "FFFFFF"; google_color_bg = "ffffff"; google_color_link = "114269"; google_color_text = "114269"; google_color_url = "114269"; </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><br /><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li>No related posts.</li>
	</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.myguideblog.com/linux/exim-cheatsheet-5733/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>15 Examples To Master Linux Command Line History</title>
		<link>http://www.myguideblog.com/linux/15-examples-to-master-linux-command-line-history-10</link>
		<comments>http://www.myguideblog.com/linux/15-examples-to-master-linux-command-line-history-10#comments</comments>
		<pubDate>Fri, 14 Nov 2008 10:42:39 +0000</pubDate>
		<dc:creator>Tony Tran</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[linux command]]></category>
		<category><![CDATA[Linux Command Line]]></category>
		<category><![CDATA[linux history]]></category>
		<category><![CDATA[master linux]]></category>

		<guid isPermaLink="false">http://www.myguideblog.com/?p=10</guid>
		<description><![CDATA[When you are using Linux command line frequently, using the history effectively can be a major productivity boost. In fact, once you have mastered the 15 examples that I’ve provided here, you’ll find using command line more enjoyable and fun.
1. Display timestamp using HISTTIMEFORMAT
Typically when you type history from command line, it displays the command# [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.myguideblog.com/wp-content/uploads/2008/11/bash-command-line.jpg"><img class="size-medium wp-image-11 alignleft" title="bash-command-line" src="http://www.myguideblog.com/wp-content/uploads/2008/11/bash-command-line.jpg" alt="" width="200" height="150" /></a>When you are using Linux command line frequently, using the history effectively can be a major productivity boost. In fact, once you have mastered the 15 examples that I’ve provided here, you’ll find using command line more enjoyable and fun.</p>
<h3>1. Display timestamp using HISTTIMEFORMAT</h3>
<p>Typically when you type history from command line, it displays the command# and the command. For auditing purpose, it may be beneficial to display the timepstamp along with the command as shown below.</p>
<pre># <strong>export HISTTIMEFORMAT=’%F %T ‘</strong>
# <strong>history | more</strong>
1  2008-08-05 19:02:39 service network restart
2  2008-08-05 19:02:39 exit
3  2008-08-05 19:02:39 id
4  2008-08-05 19:02:39 cat /etc/redhat-release</pre>
<h3>2. Search the history using Control+R</h3>
<p>I strongly believe, this may be your most frequently used feature of history. When you’ve already executed a very long command, you can simply search history using a keyword and re-execute the same command without having to type it fully. <strong>Press Control+R and type the keyword</strong>. In the following example, I searched for <strong>red</strong>, which displayed the previous command “<strong>cat /etc/redhat-release</strong>” in the history that contained the word red.</p>
<pre># <span style="color: red;">[Press <strong>Ctrl+R</strong> from the command prompt,
which will display the reverse-i-search prompt]</span>
(reverse-i-search)`<strong>red</strong>‘: cat /etc/redhat-release
<span style="color: red;">[Note: Press <strong>enter when you see your command</strong>,
which will execute the command from the history]</span>
# cat /etc/redhat-release
Fedora release 9 (Sulphur)</pre>
<p>Sometimes you want to edit a command from history before executing it. For e.g. you can search for <strong>httpd</strong>, which will display <strong>service httpd stop</strong> from the command history, select this command and <strong>change the stop to start</strong> and re-execute it again as shown below.</p>
<pre># <span style="color: red;">[Press <strong>Ctrl+R</strong> from the command prompt,
which will display the reverse-i-search prompt]</span>
(reverse-i-search)`<strong>httpd</strong>‘: service httpd stop
<span style="color: red;">[Note: Press <strong>either left arrow or right arrow</strong> key when you see your
command, which will display the command for you to edit, before executing it]</span>
# service httpd start</pre>
<h3>3. Repeat previous command quickly using 4 different methods</h3>
<p>Sometime you may end up repeating the previous commands for various reasons. Following are the 4 different ways to repeat the last executed command.</p>
<ol>
<li>Use the <strong>up arrow</strong> to view the previous command and press enter to execute it.</li>
<li>Type <strong>!!</strong> and press enter from the command line</li>
<li>Type <strong>!-1</strong> and press enter from the command line.</li>
<li>Press <strong>Control+P</strong> will display the previous command, press enter to execute it</li>
</ol>
<h3>4. Execute a specific command from history</h3>
<p>In the following example, If you want to repeat the command #4, you can do <strong>!4</strong> as shown below.</p>
<pre># <strong>history | more</strong>
1  service network restart
2  exit
3  id
4  cat /etc/redhat-release

# <strong>!4</strong>
cat /etc/redhat-release
Fedora release 9 (Sulphur)</pre>
<h3>5. Execute previous command that starts with a specific word</h3>
<p>Type ! followed by the starting few letters of the command that you would like to re-execute. In the following example, typing !ps and enter, executed the previous command starting with ps, which is ‘ps aux | grep yp’.</p>
<pre># <strong>!ps</strong>
ps aux | grep yp
root     16947  0.0  0.1  36516  1264 ?        Sl   13:10   0:00 ypbind
root     17503  0.0  0.0   4124   740 pts/0    S+   19:19   0:00 grep yp</pre>
<h3>6. Control the total number of lines in the history using HISTSIZE</h3>
<p>Append the following two lines to the .bash_profile and relogin to the bash shell again to see the change. In this example, only 450 command will be stored in the bash history.</p>
<pre># <strong>vi ~/.bash_profile</strong>
HISTSIZE=450
HISTFILESIZE=450</pre>
<h3>7. Change the history file name using HISTFILE</h3>
<p>By default, history is stored in <strong>~/.bash_history</strong> file. Add the following line to the .bash_profile and relogin to the bash shell, to store the history command in .commandline_warrior file instead of .bash_history file. I’m yet to figure out a practical use for this. I can see this getting used when you want to track commands executed from different terminals using different history file name.</p>
<pre># <strong>vi ~/.bash_profile</strong>
HISTFILE=/root/.commandline_warrior</pre>
<p>If you have a good reason to change the name of the history file, please share it with me, as I’m interested in finding out how you are using this feature.</p>
<h3>8. Eliminate the continuous repeated entry from history using HISTCONTROL</h3>
<p>In the following example pwd was typed three times, when you do history, you can see all the 3 continuous occurrences of it. To eliminate duplicates, set HISTCONTROL to ignoredups as shown below.</p>
<pre># <strong>pwd</strong>
# <strong>pwd</strong>
# <strong>pwd</strong>
# <strong>history | tail -4</strong>
44  pwd
45  pwd
46  pwd <span style="color: red;">[Note that there are <strong>three pwd</strong> commands in history, after
executing pwd 3 times as shown above]</span>
47  history | tail -4

# <strong>export HISTCONTROL=ignoredups</strong>
# <strong>pwd</strong>
# <strong>pwd</strong>
# <strong>pwd</strong>
# <strong>history | tail -3</strong>
56  export HISTCONTROL=ignoredups
57  pwd <span style="color: red;">[Note that there is only <strong>one pwd</strong> command in the history, even after
executing pwd 3 times as shown above]</span>
58  history | tail -4</pre>
<h3>9. Erase duplicates across the whole history using HISTCONTROL</h3>
<p>The ignoredups shown above removes duplicates only if they are consecutive commands. To eliminate duplicates across the whole history, set the HISTCONTROL to erasedups as shown below.</p>
<pre># <strong>export HISTCONTROL=erasedups</strong>
# <strong>pwd</strong>
# <strong>service httpd stop</strong>
# <strong>history | tail -3</strong>
38  pwd
39  service httpd stop
40  history | tail -3

# <strong>ls -ltr</strong>
# <strong>service httpd stop</strong>
# <strong>history | tail -6</strong>
35  export HISTCONTROL=erasedups
36  pwd
37  history | tail -3
38  ls -ltr
39  service httpd stop
<span style="color: red;">[Note that the previous service httpd stop after pwd got erased]</span>
40  history | tail -6</pre>
<h3>10. Force history not to remember a particular command using HISTCONTROL</h3>
<p>When you execute a command, you can instruct history to ignore the command by setting HISTCONTROL to ignorespace AND typing a space in front of the command as shown below. I can see lot of junior sysadmins getting excited about this, as they can hide a command from the history. It is good to understand how ignorespace works. But, as a best practice, don’t hide purposefully anything from history.</p>
<pre># <strong>export HISTCONTROL=ignorespace</strong>
# <strong>ls -ltr</strong>
# <strong>pwd</strong>
# <strong> service httpd stop</strong> <span style="color: red;">[Note that there is a space at the beginning of service,
to ignore this command from history]</span>
# <strong>history | tail -3</strong>
67  ls -ltr
68  pwd
69  history | tail -3</pre>
<h3>11. Clear all the previous history using option -c</h3>
<p>Sometime you may want to clear all the previous history, but want to keep the history moving forward.</p>
<pre># <strong>history -c</strong></pre>
<h3>12. Subtitute words from history commands</h3>
<p>When you are searching through history, you may want to execute a different command but use the same parameter from the command that you’ve just searched.</p>
<p>In the example below, the <strong>!!:$</strong> next to the vi command gets the argument from the previous command to the current command.</p>
<pre># <strong>ls anaconda-ks.cfg</strong>
anaconda-ks.cfg
# <strong>vi !!:$</strong>
vi anaconda-ks.cfg</pre>
<p>In the example below, the <strong>!^</strong> next to the vi command gets the first argument from the previous command (i.e cp command) to the current command (i.e vi command).</p>
<pre># <strong>cp anaconda-ks.cfg anaconda-ks.cfg.bak</strong>
anaconda-ks.cfg
# <strong>vi -5 !^</strong>
vi anaconda-ks.cfg</pre>
<h3>13. Substitute a specific argument for a specific command.</h3>
<p>In the example below, <strong>!cp:2</strong> searches for the previous command in history that starts with cp and takes the second argument of cp and substitutes it for the ls -l command as shown below.</p>
<pre># <strong>cp ~/longname.txt /really/a/very/long/path/long-filename.txt</strong>
# <strong>ls -l !cp:2</strong>
ls -l /really/a/very/long/path/long-filename.txt</pre>
<p>In the example below, <strong>!cp:$</strong> searches for the previous command in history that starts with cp and takes the last argument (in this case, which is also the second argument as shown above) of cp and substitutes it for the ls -l command as shown below.</p>
<pre># <strong>ls -l !cp:$</strong>
ls -l /really/a/very/long/path/long-filename.txt</pre>
<h3>14. Disable the usage of history using HISTSIZE</h3>
<p>If you want to disable history all together and don’t want bash shell to remember the commands you’ve typed, set the HISTSIZE to 0 as shown below.</p>
<pre># <strong>export HISTSIZE=0</strong>
# <strong>history</strong>
# <span style="color: red;">[Note that history did not display anything]</span></pre>
<h3>15. Ignore specific commands from the history using HISTIGNORE</h3>
<p>Sometimes you may not want to clutter your history with basic commands such as pwd and ls. Use HISTIGNORE to specify all the commands that you want to ignore from the history. Please note that adding ls to the HISTIGNORE ignores only ls and not ls -l. So, you have to provide the exact command that you would like to ignore from the history.</p>
<pre># <strong>export HISTIGNORE=”pwd:ls:ls -ltr:”</strong>
# <strong>pwd</strong>
# <strong>ls</strong>
# <strong>ls -ltr</strong>
# <strong>service httpd stop</strong>

# <strong>history | tail -3</strong>
79  export HISTIGNORE=”pwd:ls:ls -ltr:”
80  service httpd stop
81  history
<span style="color: red;">[Note that history did not record pwd, ls and ls -ltr]</span></pre>

	Tags: <a href="http://www.myguideblog.com/category/linux" title="Linux" rel="tag">Linux</a>, <a href="http://www.myguideblog.com/tag/linux-command" title="linux command" rel="tag">linux command</a>, <a href="http://www.myguideblog.com/tag/linux-command-line" title="Linux Command Line" rel="tag">Linux Command Line</a>, <a href="http://www.myguideblog.com/tag/linux-history" title="linux history" rel="tag">linux history</a>, <a href="http://www.myguideblog.com/tag/master-linux" title="master linux" rel="tag">master linux</a><br /><script type="text/javascript"> google_ad_client = "pub-9646538075083871"; google_ad_channel ="3089257411"; google_ad_width = 468; google_ad_height = 15; google_ad_format = "468x15_0ads_al"; google_color_border = "FFFFFF"; google_color_bg = "ffffff"; google_color_link = "114269"; google_color_text = "114269"; google_color_url = "114269"; </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><br /><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.myguideblog.com/linux/command-to-check-hardware-6367" title="Command to check hardware (March 3, 2009)">Command to check hardware</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.myguideblog.com/linux/15-examples-to-master-linux-command-line-history-10/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
