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.

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
 

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 :