当Linux 进行查找时,对某些目录的访问可能没有权限而无法进行访问,打印出很多错误消息
1、root目录文件内容
-bash-3.2$ ls
anaconda-ks.cfg bea Desktop lib wls1036_generic.jar
2、查找.log结尾的文件,
-bash-3.2$ find . -name "*.log"
find: ./.gconfd: ?é???¤
find: ./.gnome2: ?é???¤
find: ./.gnome2_private: ?é???¤
find: ./.Trash: ?é???¤
find: ./.java: ?é???¤
find: ./.tuscany: ?é???¤
find: ./.eggcups: ?é???¤
find: ./.chewing: ?é???¤
find: ./.mozilla/firefox: ?é???¤
find: ./.scim: ?é???¤
find: ./.metacity: ?é???¤
find: ./.gconf: ?é???¤
find: ./.nautilus/metafiles: ?é???¤
这时系统语言使用中文反而有问题,很奇怪
-bash-3.2$ echo $LANG
zh_CN.UTF-8
临时改为英文
-bash-3.2$ export LANG="en_US.UTF-8"
-bash-3.2$ echo $LANG
en_US.UTF-8
然后再查找
-bash-3.2$ find . -name "*.log"
find: ./.gconfd: Permission denied
find: ./.gnome2: Permission denied
find: ./.gnome2_private: Permission denied
find: ./.Trash: Permission denied
find: ./.java: Permission denied
find: ./.tuscany: Permission denied
find: ./.eggcups: Permission denied
find: ./.chewing: Permission denied
find: ./.mozilla/firefox: Permission denied
find: ./.scim: Permission denied
find: ./.metacity: Permission denied
find: ./.gconf: Permission denied
find: ./.nautilus/metafiles: Permission denied
3、将错误输出到/dev/null装置上,错误信息消失
-bash-3.2$ find . -name "*.log" 2>/dev/null
-bash-3.2$ find . -name "*.cfg" 2>/dev/null
./anaconda-ks.cfg
Linux find 去除错误消息,布布扣,bubuko.com
原文地址:http://blog.csdn.net/hongweigg/article/details/37818697