MySQL Backup and Restore – Using Command Line

Here is how you backup database using command line. The first line is to backup and the second line is to restore.
These commands work on both Windows and Linux. In Windows you might want to setup the environment PATH, you can do this easily by pressing Window + Break > Advanced System Settings > Environment > PATH. Then run the cmd or the command prompt. If you already open a command prompt before you setup the PATH, you need to restart your command prompt

1
2
$ mysqldump -uusername -ppassword database_name > YOURSQLFILE.sql
$ mysql -uusername -ppassword database_name < YOURSQLFILE.sql
Posted in Database, Linux, MySQL | Leave a comment

Delete All Symlink in The Current Directory

find . -maxdepth 1 -type l -exec rm -f {} \;

Posted in Linux, Operating System | Leave a comment

Ad Blocker for Android Browser

If you’re anoyed with ads in your android browser, you should try Ad Block:
https://market.android.com/details?id=de.ub0r.android.adBlock&hl=en
With ad block your browser will make a request through a proxy server, which is the Ad Block itself. The Ad Block usually setup to use host 127.0.0.1 also known as the localhost, and port 8080.

In order to access the android default proxy settings you need a shortcut to the settings, which by default its hidden. So you’ll need Any Cut
https://market.android.com/details?id=com.appdroid.anycut&hl=en

The cool thing is no rooting required. This way you can browse faster, safer, and use less bandwidth.

Posted in Android | Leave a comment

Benchmark How Long a Program Runs In Linux Using Bash

The following bash code might come handy for those of you who want to benchmark how long does a program runs.
In the following example the assumption is that you want to pass along two parameters for your program to run properly.
A time will be recorded at the beginning and at the end of the execution. And a time diff, the processing time, will be reported in seconds.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
##################################################
# Benchmark the processing time when a program
# executes with two required parameters: parameter1 parameter2
##################################################

if [[ $1 = "" || $2 = "" ]]; then
        echo "Usage: `basename $0` parameter1 parameter2"
else
        _start_time=`date +%s`
        _parameter1=$1
        _parameter2=$2
        ### YOUR COMMAND HERE WITH parameter1 AND parameter2 ###
        _end_time=`date +%s`
        _processing_time=$((_end_time-_start_time))
        echo "Source File: $_parameter1"
        echo "Destination File: $_parameter2"
        echo "Start time: $_start_time"
        echo "End time: $_end_time"
        echo "Processing time is: $_processing_time"
fi
Posted in Linux, Operating System, Ubuntu | Leave a comment

Auto Login Using SSH Public and Private Keys

Assume that your main server (the one you use the most) is serverA.
And serverA wants to automatically login to serverB

1. At serverB issue: # ssh-keygen -t rsa
This will create a public + ptivate key for serverB
2. Enter (empty) for paraphrase
Your identification has been saved in /home/ronald/.ssh/id_rsa.
Your public key has been saved in /home/ronald/.ssh/id_rsa.pub.
3. Copy over the newly created public key at serverB to serverA
scp .ssh/id_rsa.pub ronald@serverA:~/id_rsa.pub.serverB

serverB public key will be copied over to serverA user home directory

4. Ssh to serverA, and issue this command:
cat id_rsa.pub.serverB >> .ssh/authorized_keys
serverB public key will be merged to serverA authorized_keys file. A file that shows that

Posted in Linux, Operating System, Ubuntu | Leave a comment

Linux Soft Symlink Folder or Directory


$ ln -s /home/rpringad/somefolder /home/rpringad/newfolder

#or if your current directory is already /home/rpringad:
$ ln -s /home/rpringad/somefolder /home/rpringad/newfolder

$ ln -s existingSourceFolder newLinkedFolder

Posted in Linux, Operating System, Ubuntu | Leave a comment

How To Know Which Linux Distribution You Are Using?

There are three commands that you can use, pick one of them:

1
2
3
4
5
cat /etc/issue

cat /proc/version

dmesg | head -1
Posted in Uncategorized | Leave a comment

Extract a compressed file on Linux (Unzip/Untar)

To extract a tar (Tape ARchiver) file, type the following in the shell prompt:
tar xvjf yourFileName.tar.bz2

Which will untar it to the current directory. Depending on the file structure that being compressed, it might create sub-directories.
Parameters:
x – extract
v – verbose output (lists all files as they are extracted)
j – deal with bzipped file
f – read from a file, rather than a tape device

Posted in Linux, Operating System | Leave a comment

How to Set up an FTP Server in Ubuntu Linux

Login to your Linux shell menu as root

1
2
[root@locahost]# apt-get install vsftpd
[root@locahost]# vim /etc/vsftpd.conf

At VIM, 1st comment out anonymous_enable by adding a # sign at the beginning of the line
# anonymous_enable=YES
2nd remove comment at local enable by removing the # sign
local_enable=YES

1
[root@locahost]# /etc/init.d/vsftpd restart
Posted in Linux, Operating System, Ubuntu | Leave a comment

Adding color to your tail

Tail is a very useful tool for monitoring error stream. Sometime the output from tail can have too much information and its black and white monotone output can be hard to follow with the eyes.
With the help of perl, which most likely comes with all linux distros, here is a way to colorize your tail output. Lets’ assume that every time you log something you will have a date-time prefixing your log. For example:

[22-Dec-2011 20:28:45] E_DATASOMETHING ……
Too much information …….
Too much information …….
[22-Dec-2011 20:28:46] E_FATAL Something
Too much information …….
Too much information …….
Too much information …….

Lets create a script that can colorize the date portion.
Create an executable linux bash file:

1
2
3
$ touch logwatch.sh
$ chmod 755 logwatch.sh
$ vim logwatch.sh

The copy and paste the following to your empty logwatch.sh

1
2
3
#!/bin/bash
vNow=$(date +"%d-%b-%Y")
tail -f ~username/errorlogfile.txt|perl -pe "s/$vNow/\e[1;30;32m$&\e[0m/g"

Voilà!

[22-Dec-2011 20:28:45] E_DATASOMETHING ……
Too much information …….
Too much information …….
[22-Dec-2011 20:28:46] E_FATAL Something
Too much information …….
Too much information …….
Too much information …….

Posted in Linux, Operating System, Uncategorized | 1 Comment