Tag Archives: unix

write — send a message to another user

A UNIX Command
$bsd-write jeffrin 8
bsd-write: jeffrin is not logged in on 8
$bsd-write jeffrin tty8
bsd-write: jeffrin has messages disabled on tty8
$mesg y
$bsd-write jeffrin tty8
bsd-write: jeffrin has messages disabled on tty8
$w
 20:08:58 up 23 min,  3 users,  load average: 0.02, 0.15, 0.16
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1                      19:46   22:18   0.35s  0.03s wpa_supplicant -iwlan0 -c /etc/wpa_
jeffrin  tty8     :0               19:53   23:20  58.84s  0.09s x-session-manager
jeffrin  pts/0    :0.0             20:01    0.00s  0.30s  0.00s w
$bsd-write jeffrin pts/0

Message from jeffrin@debian.BW on pts/0 at 20:09 ...
hey ... worked ?
hey ... worked ?
EOF
$

UNIX Explanation
If the  user you want  to write to  is logged in  on more
than  one terminal,  you  can specify  which terminal  to
write to  by specifying the  terminal name as  the second
operand to the write command.  Alternatively, you can let
write select one of the  terminals - it will pick the one
with the shortest idle time.  This is so that if the user
is logged  in at work and  also dialed up  from home, the
message will go to the right place.

truncate – shrink or extend the size of a file to the specified size

A UNIX Command

$cat example.text 
hello
$ls -l example.text 
-rw-r--r-- 1 jeffrin jeffrin 6 Jun 21 02:32 example.text
$truncate -s 10 example.text 
$ls -l example.text 
-rw-r--r-- 1 jeffrin jeffrin 10 Jun 21 02:35 example.text
$hexdump example.text 
0000000 6568 6c6c 0a6f 0000 0000               
000000a
$cat example.text 
hello
$truncate -s 9 example.text 
$ls -l example.text 
-rw-r--r-- 1 jeffrin jeffrin 9 Jun 21 02:36 example.text
$hexdump example.text 
0000000 6568 6c6c 0a6f 0000 0000               
0000009
$

UNIX Explanation

`truncate' shrinks  or extends the  size of each  FILE to
the specified size.If a FILE is larger than the specified
size, the extra  data is lost.  If a  FILE is shorter, it
is extended and the extended part (or hole) reads as zero
bytes.