Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This is in one of the rc scripts in Red Hat and I want to understand the purpose of > /dev/tty[n]

 last=0
 for i in `LC_ALL=C grep '^[0-9].*respawn:/sbin/mingetty' /etc/inittab | sed 's/^.* tty\([0-9][0-9]*\).*/\1/g'`; do    
 > /dev/tty$i
 last=$i

To simplify the question for those having trouble understanding the script, what does the following code do exactly? (it seems to send a null value to /dev/tty but why?)

> /dev/tty1
> /dev/tty2
share|improve this question
    
I understand all of the rest of it, but I want to know only about the 3rd line. –  user160910 Apr 23 '13 at 15:06
1  
Which rc script? –  larsks Apr 23 '13 at 15:28
    
Are you sure you got the spacing correct in the sed bit? This looks wrong, there appears to be spaces where there shouldn't be. 's/^.* tty\ ([0- 9][0-9]*\).*/\1/g. –  Zoredache Apr 23 '13 at 16:33
    
The formatting got screwy when I copied it here, I fixed the spacing. This is the rc.sysinit script. Anyone know the answer to my question? –  user160910 Apr 23 '13 at 18:30
add comment

1 Answer

up vote 0 down vote accepted

It outputs text to Linux virtual console N (Ctrl_Alt_n). In snippet you've quoted this would redirect output to every Linux Virtual Console supposed to have mingetty run on.

UPD.:

(it seems to send a null value to /dev/tty but why?)

This might have a purpose of virtual consoles initialization — man 4 console:

Before kernel version 1.1.54 the number of virtual consoles was compiled into the kernel (in tty.h: #define NR_CONSOLES 8) and could be changed by editing and recompiling. Since version 1.1.54 virtual consoles are created on the fly, as soon as they are needed.

— so, yep, it looks like on-demand creation.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.