One command called ‘clear’
You must have used the command ‘clear(1)’ to clear your terminal. Well, if you haven’t, please try it out. For those who know what it is, do you know how it works ? If you do, you can stop reading. Others, continue!
Well, I wanted to find out how it works. So the first thing I did was an strace to see what syscalls it did..
[root@cff ~]# strace clear
and I was left with..
) = 7 exit_group(0) = ? [root@cff ~]#
Well, it did clear the screen! I tried to redirect the output to a file. No use. An interesting idea struck me. What will happen if I redirect output of clear, I thought..
[root@cff ~]# clear > out [root@cff ~]#
Wow! It didn’t clear the screen.. Let me see what’s in the file.. vim didn’t work out well. I used od.
[root@cff ~]# od -bc out 0000000 033 133 110 033 133 062 112 033 [ H 033 [ 2 J 0000007 [root@cff ~]#
Some weird ascii characters. Now, I did ‘cat out’ and I was surprised to see the terminal cleared! Wow!
Now even better, I wanted to use echo and clear the screen. Going through the echo manual, I found out how to do it. Here it is. Please replace <zero> with a 0. This damn wordpress for an unknown reason does not allow me to put a 0 in there.
echo -e "\<zero>33[H\<zero>33[2J"
Execute this, and your terminal will be cleared.
If it didn’t, you have to do all the steps I performed and find out the byte sequence that will clear your terminal. Good luck!




nais..
tried it in windows
here’s the octal dump “0000000 000014
0000001″
cat out didn’t work. ported linux tools in windnows..
aditya
December 5, 2008
@aditya,
Hmmm.. Don’t know about Windows
I would say Unsupported!
balajirrao
December 6, 2008
[...] the lines of the previous post One command called ‘clear’, I wrote a small C program that does [...]
clrscr in linux! « Brain Dump
December 6, 2008