歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

Linuxfind去除錯誤消息

當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

Copyright © Linux教程網 All Rights Reserved