LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1228|回复: 2

黑洞有什么用?

[复制链接]
发表于 2004-5-24 08:45:37 | 显示全部楼层 |阅读模式
/dev/null这个有什么用?想用他临时存点东西都不行,是不是只有在编程的时候才有用,在一般的bash下就没有什么用了?能举例子说明一下吗?
发表于 2004-5-24 09:40:55 | 显示全部楼层
形象地说,/dev/null是数据的焚化炉,任何重定向到/dev/null的输出都会被丢弃。
比如说,我们在启动脚本中执行一个命令,但不需要它的输出,而只想要它的返回状态以便控制程序的流程。这时候使用

  1. command >/dev/null 2>&1
  2. if [ $? -eq 0 ]; then
  3. # statement when command exit normally
  4. fi
复制代码

/dev/null还有另外一个用途,用来清空文件的内容。

  1. cat /dev/null > file
复制代码


/dev/null在shell代码中用得比较多,至于C的系统编程,不会用到它。
发表于 2004-5-25 19:48:33 | 显示全部楼层
  1.        Data written on a null or zero special file is discarded.

  2.        Reads  from  the  null  special file always return end of file, whereas
  3.        reads from zero always return \0 characters.
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表