Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Jan 272010
 

How to rename database in MySQL

Answer:

If you are using MyISAM storage engine, the easiest way is to take down the MySQL server and rename the database folder name.

Else, you can use the mysqldump tool, steps as following:

1. Export the database using mysqldump tool

# mysqldump -u root -p old_db > old_db.sql

2. Create a new database

# mysql -u root -p -e 'create database new_db'

3. Finally import into the new database

# cat old_db.sql |mysql -u root -p new_db
Jan 262010
 

wget with rate limiting

Answer:

When you are downloading a large file, and you want to limit the bandwidth used, it is easy with the wget command

wget --limit-rate=100k http://www.example.com/file.zip

The above command will limit the rate to be used not to exceed 100kbps.

Jan 262010
 

Print a particular column data using awk

Answer:

Consider you have a file text.txt like below

1 one
2 two
3 three

How would you only print the second column?

It can be easily done using awk

# awk '{print $2}' text.txt
one
two
three

Try the above command with $1, $2, $3 etc.

Jan 262010
 

How to sort IP addresses in Linux

Answer:

When you have a file ip.txt contains a list of IP addresses, e.g.

127.0.0.2
127.0.0.1
10.10.10.1

To sort it, you can use the following command

# sort -t. -k1,1n -k2,2n -k3,3n -k4,4n ip.txt

10.10.10.1
127.0.0.1
127.0.0.2