Linux find 去除错误消息

当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 去除错误消息,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。