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

你可能感兴趣的:(OS)