Linux系统终端由控制码、一个环境变量和一组共称为terminfo数据库的特殊文件来实现的。Linux系统将每种终端类型的terminfo数据作为一个单独的文件存储在terminfo数据库目录。常见的位置有 /usr/share/terminfo/、/usr/share/terminfo/、/etc/terminfo/。
[root@iZ259w678ctZ 2015-12-01]# ls /usr/share/terminfo/ a A c d e E g h j k l m n p r s t v w x [root@iZ259w678ctZ 2015-12-01]# ll /usr/share/terminfo/ total 80 drwxr-xr-x. 2 root root 4096 Aug 14 2014 a drwxr-xr-x. 2 root root 4096 Aug 14 2014 A drwxr-xr-x. 2 root root 4096 Aug 14 2014 c drwxr-xr-x. 2 root root 4096 Aug 14 2014 d drwxr-xr-x. 2 root root 4096 Aug 14 2014 e drwxr-xr-x. 2 root root 4096 Aug 14 2014 E drwxr-xr-x. 2 root root 4096 Aug 14 2014 g drwxr-xr-x. 2 root root 4096 Aug 14 2014 h drwxr-xr-x. 2 root root 4096 Aug 14 2014 j drwxr-xr-x. 2 root root 4096 Aug 14 2014 k drwxr-xr-x. 2 root root 4096 Aug 14 2014 l drwxr-xr-x. 2 root root 4096 Aug 14 2014 m drwxr-xr-x. 2 root root 4096 Aug 14 2014 n drwxr-xr-x. 2 root root 4096 Aug 14 2014 p drwxr-xr-x. 2 root root 4096 Aug 14 2014 r drwxr-xr-x. 2 root root 4096 Aug 14 2014 s drwxr-xr-x. 2 root root 4096 Aug 14 2014 t drwxr-xr-x. 2 root root 4096 Aug 14 2014 v drwxr-xr-x. 2 root root 4096 Aug 14 2014 w drwxr-xr-x. 2 root root 4096 Aug 14 2014 x [root@iZ259w678ctZ 2015-12-01]# ll /etc/terminfo/ total 0 [root@iZ259w678ctZ 2015-12-01]# ls /etc/terminfo/ [root@iZ259w678ctZ 2015-12-01]# ls /lib/terminfo/ a d l v [root@iZ259w678ctZ 2015-12-01]# ls /usr/share/terminfo/v/ vs100 vt100 vt100-am vt100-nav vt102 vt200 vt220 vt52
terminfo数据库文件是二进制的,可以用infocmp命令将二进制条目转换成文本,如下:
[root@iZ259w678ctZ 2015-12-01]# cd /usr/share/terminfo/ [root@iZ259w678ctZ terminfo]# infocmp vt100 #Reconstructed via infocmp from file: /usr/share/terminfo/v/vt100 vt100|vt100-am|dec vt100 (w/advanced video), am, mc5i, msgr, xenl, xon, cols#80, it#8, lines#24, vt#3, acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, bel=^G, blink=\E[5m$<2>, bold=\E[1m$<2>, clear=\E[H\E[J$<50>, cr=^M, csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H, cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C$<2>, cup=\E[%i%p1%d;%p2%dH$<5>, cuu=\E[%p1%dA, cuu1=\E[A$<2>, ed=\E[J$<50>, el=\E[K$<3>, el1=\E[1K$<3>, enacs=\E(B\E)0, home=\E[H, ht=^I, hts=\EH, ind=^J, ka1=\EOq, ka3=\EOs, kb2=\EOr, kbs=^H, kc1=\EOp, kc3=\EOn, kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, kent=\EOM, kf0=\EOy, kf1=\EOP, kf10=\EOx, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\EOt, kf6=\EOu, kf7=\EOv, kf8=\EOl, kf9=\EOw, lf1=pf1, lf2=pf2, lf3=pf3, lf4=pf4, mc0=\E[0i, mc4=\E[4i, mc5=\E[5i, rc=\E8, rev=\E[7m$<2>, ri=\EM$<5>, rmacs=^O, rmam=\E[?7l, rmkx=\E[?1l\E>, rmso=\E[m$<2>, rmul=\E[m$<2>, rs2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, sc=\E7, sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;$<2>, sgr0=\E[m\017$<2>, smacs=^N, smam=\E[?7h, smkx=\E[?1h\E=, smso=\E[7m$<2>, smul=\E[4m$<2>, tbc=\E[3g,
附上terminfo功能代码: