Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1879845
  • 博文数量: 217
  • 博客积分: 4362
  • 博客等级: 上校
  • 技术积分: 4180
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-20 09:31
文章分类

全部博文(217)

文章存档

2017年(1)

2015年(2)

2014年(2)

2013年(6)

2012年(42)

2011年(119)

2010年(28)

2009年(17)

分类: Python/Ruby

2011-08-11 08:22:13

这三个文件都是字符设备文件。

(1)/dev/console
/dev/console代表的系统控制台,错误信息和诊断信息都会被到这个上。
(2)/dev/tty
/dev/tty如果一个控制台有一个终端的话,那么这个文件就是对应的当前的这个控制终端的别名
注:console和tty有很大区别:console是个只输出的设备,功能很简单,只能在内核中访问;tty是char设备,可以被用户程序访问。
(3)/dev/null
这个是一个空设备文件,所有写到这个文件中的数据都会被丢弃掉
注:/dev/zero会提供无穷无尽的0,它可以给文件写入无穷无尽的0,例如:
  1. ^_^[sunny@sunny-laptop ~/summer/shell]32$ dd if=/dev/zero of=mydoc.txt bs=100k count=1
  2. 记录了1+0 的读入
  3. 记录了1+0 的写出
  4. 102400字节(102 kB)已复制,0.000571359 秒,179 MB/
  5. ^_^[sunny@sunny-laptop ~/summer/shell]33$ ls -lsh
  6. 总用量 108K
  7. 104K -rw-r--r-- 1 sunny sunny 100K 2011-08-11 08:37 mydoc.txt
  8. 4.0K -rwxr--r-- 1 sunny sunny 65 2011-08-11 08:36 test.sh
  9. ^_^[sunny@sunny-laptop ~/summer/shell]34$
我们可以通过输入密码的一个shell脚本测试一下/dev/tty
  1. ^_^[sunny@sunny-laptop ~/summer/shell]34$ cat test.sh
  2. #!/bin/bash
  3. stty -echo
  4. read pass < /dev/tty
  5. echo $pass
  6. stty echo
  7. ^_^[sunny@sunny-laptop ~/summer/shell]35$ ./test.sh
  8. abcdefg
  9. ^_^[sunny@sunny-laptop ~/summer/shell]36$
注意,在这里输入密码的时候,我使用stty命令屏蔽掉了输入回显示的功能。


阅读(4114) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~