我们都知道Linux下万物皆文件,主要包括:-普通文件d目录l符号链接s套接字b块设备c字符设备p管道等等。这里的前缀字符可以通过ls命令观察到:$ls-ltest.log-rw-r--r--1rootroot33Nov1717:03test.log它的结果是第一个-,所以是一个普通文件。$ls-al/dev/nullcrw-rw-rw-1rootroot1,3Sep1120:33/dev/null其结果前面有c,所以是字符设备。该文件简单介绍了几个字符设备文件,可以在我们进行功能测试时提供很好的帮助。/dev/null/dev/null可以无限接收数据,你可以把它想象成一个黑洞,所以如果我们需要丢弃一些终端输出,我们可以重定向到这里:$echo"shouwangxiansheng">/dev/null所以如果你有不需要的数据可以在这里写多少就写多少。/dev/full读的时候会读取一个连续的NUL(零值)字节流,写的时候会返回磁盘空间已满的结果,对你测试程序的时候有帮助,就是场景其中测试盘已满:$echo"bianchengzhuji">/dev/full-bash:echo:writererror:Nospaceleftondevice/dev/zero类似于/dev/null,写入时所有数据都会被丢弃,但是读取时,一个NUL(零值)字节流被产生。$cat/dev/zero|od-x00000000000000000000000000000000000000/dev/random/dev/randomcanproviderandomdataflow,whichguaranteestherandomnessofdata,butitwillcausewaitingwhenreading,forexample:$cat/dev/random|od-x00000002b07daac42f4e1fdfb622098870ee0af000002030222099e5da4e1cd6db548ba979121700000403777bb6a957d1279ab29e8a46a36ecca000006039ec2285126c30eaea6715265e4a2dd9稍过会才会出现数据,为了便于查看,我们利用od命令查看其十六进制内容。/dev/urandomcanbeseenfromthename,itisusedtogeneraterandomdata.它的产生速度很快,但是数据的随机性不如/dev/randomcat/dev/urandom|od-x0547560f43e696a89362b2736c8444628021d470547600b8af249daae9edbf8971b1d10c733e2d0547620237b9a816348cb2a19724486028a357305476401690c38864e1aec1d5f41964bbb9192f0547660f242719451ba62a3fc13ff53fb50e3d80547700ef323658b33575ee62de40966468c979054772001b9c233878d12fc5cfa569189e1e1f9/dev/pts/dev/pts是远程登陆(telnet,ssh等)后创建的控制台设备文件所在Directory.Whatistheuse?Forexample,youopenaterminalandgetthecurrentpts:$tty/dev/pts/0Thenyouopenanotherone,enter:$echo"hahahaha">/dev/pts/0andyouwillYouwillfindthatthecontentisprintedtothepreviousterminal.Usuallywhenwerunaprogram,itsprintfwillbeprintedonthecurrentterminal.SummaryInfact,therearemanyspecialfilesunder/dev,butwewillnotintroducethemonebyone.Theabovespecialfilescanhelpusdeveloportestincertainoccasions.
