Posts Tagged ‘linux’

How to Change MySQL Data Directory in Linux Centos

Saturday, July 2nd, 2011

By default Linux CentOS or other Linux Distro installation, MySQL data directory is stored in /var/db/mysql, how can I change it to other directory in example /db/mysql?

It is always better to have MySQL Data Directory store in a specific partition/drive. It will help on performance and better management and scalability. You change change the data store directory in Linux by editing /etc/my.cnf file.

Edit /etc/my.cnf file


# vi /etc/my.cnf

Change the data directory structure


datadir=/db/mysql
socket=/db/mysql/mysql.sock

After the file has been updated, restart MySQL service.

How to Find Out Public IP Address via Command Line in Unix/Linux Machine

Tuesday, March 8th, 2011

If you have more than 100 servers in your network; behind a firewall; lazy to access to documentation. Here is the alternative option to find out your machine’s public IP Address via command line


$ wget -q -O - http://ipchicken.com |  grep -o -E '(^|[[:space:]])[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*([[:space:]]|$)'
# By default, FreeBSD doesn't have wget, you can use fetch instead
$ fetch -q -o - http://www.ipchicken.com | grep -o -E '(^|[[:space:]])[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*([[:space:]]|$)'

You need port 80 external/WAN access to perform the task.

How to Lock Your Machine and Display Application Screen

Friday, September 24th, 2010

We have a couple monitoring applications running on our Linux desktop. To monitor server health, graph utilization through various network monitoring systems. Usually monitoring application required authentication and it will be a security issue if you left your Linux desktop unlock.

But if you lock your Linux desktop, the screen will goes blank and you can’t monitor what is projected on your screen. There is a way to do it with screen saver lock, where you can lock your Linux desktop and at the same time to display when application is running on your monitoring screen.

Lock Your Machine with xlock

First, install xlock in your Linux desktop


shell> sudo apt-get install xlock

After xlock has been install, create a file name lockscreen, chmod to 777 and paste the line below in the file


# /usr/bin/xlock -mode image -geometry 0x0 -timeout 1
shell> vi lockscreen
shell> chmod 755 lockscreen

xlock is screen saver lock, but it can disable the screen saver screen by setting display with “-geometry 0×0″.

You can also bind your keyboard short cut key to launch the lockscreen script through System > Preferences > Keyboard Shortcuts.

How to Check Linux Version and Distro

Wednesday, July 21st, 2010

Who run more than 10 Linux servers with different version of Linux Distro? We all know there are many type of Linux distro such as Ubuntu, Centos, Gentoo, Fedora, debian, OpenSUSE and etc. Every single distro runs on different version and etc. Sometime I am having problem to remember what Linux distro is running on my DNS server or Mail Server, and what Linux version is it on now. There are two methods to find linux version on your server.

To check Linux distro on your server


shell> cat /etc/issue

To check Linux Version and distro on your server


shell> cat /etc/*-release

Linux/Unix Search and Replace Text from Multiple Files

Wednesday, July 14th, 2010

In Linux/Unix, for newbie to do search text from multiple files/folder look like difficult, replacing string from file sound even harder. It’s actually not hard or complicated to search and replace text from multiple files in Unix/Linux. The key is what command to use, there will be two main commands involve in search and replace, which are find and sed

For example I am hosting multiple web applications, the development might have several pg_connect command to connect database, in the event I am migrating database to other IP address, it might be hard for them to dig the file and replace the IP Address with new IP Addresses.

In Linux/Unix, you can search through the directories, looking for the files and replace it with the new IP address. Here is the sample.


shell> find /path/to/dir/* -type f -exec sed -i .backup20100714 -e "s/host=x.x.x.x/host=y.y.y.y/g" {} \\;

The command above will search for files in the directory.
find -type f mean look for File only.
find -exec is to execute something from returned results.
sed -i means backup the files, in case you would like to restore later.
sed -e “s/host=x.x.x.x/host=y.y.y.y/g” is to replace x.x.x.x to y.y.y.y

You have backup files name filename.php.backup20100714, now what you need to do is move the files in a backup directory.


shell> find /path/to/dir/* -name "*.backup20100714" -exec mv {} /your/backup/dir/ \\;

You might want to explore on find command, it can do a lot of cool stuffs.