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 282010
 

Spying on the physical console

Answer:

When you connect to your remote Linux server using SSH, sometimes you would like to see the message that appear in the console, you can view using the following method:

# tail -f /dev/vcs1

Where vcs1 means the virtual terminal 1, possible options are 1, 2, 3, 4 etc.

The method will save you many time from always need to visit the physical server.

Jan 282010
 

Wrap each line to fit in specified width

Answer:

If you want to format a text file into a specific width, you can use the fold command

E.g.

# fold -w 40 test.txt

The above command will wrap the text file and print to standard out, with width = 40 characters.

Jan 272010
 

Create temporary table in MySQL

Answer:

Temporary table is very useful when you need some tables for temporary storage, and they will be automatically removed when you disconnect from the MySQL server.

Steps:

1. Create a temporary table

mysql> CREATE TEMPORARY TABLE test (id int); 

2. Insert some values

mysql> INSERT INTO test VALUES (1);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO test VALUES (2);
Query OK, 1 row affected (0.00 sec)

3. Query the table

mysql> SELECT * FROM test

+------+
| id   |
+------+
|    1 |
|    2 |
+------+
2 rows in set (0.00 sec)

4. Close the connection and the table will be automatically removed.

Jan 272010
 

How to connect MySQL without using password

Answer:

1. Create a .my.cnf in your home folder

# vi ~/.my.cnf

2. Enter your MySQL login information and save the file.

[client]
user=john
password=john_password

3. Try typing mysql in shell and you should able to login automatically.

Jan 272010
 

Extract column data using awk

Answer:

A simple awk command print the 1st column of top command

# top -bc -n1 | awk '{print $1}'

If you want to specify the field separator, you can do the following

# awk -F':' '{print $1}' /etc/passwd

Which print the 1st column of file /etc/password, as if they are split by :