auth.log 视为二进制文件

auth.log 视为二进制文件

我尝试使用 grep 查看 auth.log

user@hos:~$ sudo grep 'sshd' /var/log/auth.log
Binary file /var/log/auth.log matches

它提示 auth.log 是一个二进制文件,但是

user@host~$ sudo tail -n 3 /var/log/auth.log
Jan 24 15:19:53 assistant sudo: pam_unix(sudo:session): session opened for user root by assistant(uid=0)
Jan 24 15:19:53 assistant sudo: pam_unix(sudo:session): session closed for user root
Jan 24 15:20:04 assistant sudo: assistant : TTY=pts/0 ; PWD=/home/assistant ; USER=root ; COMMAND=/usr/bin/tail -n 3 /var/log/auth.log

当来到猫

user@host:~$ sudo cat /var/log/auth.log | grep 'sshd'
Binary file (standard input) matches

为什么auth.log被视为二进制文件?

答案1

man grep

--binary-files=TYPE
      If  a  file's  data or metadata indicate that the file contains binary data, assume
      that the file is of type TYPE.  Non-text bytes  indicate  binary  data;  these  are
      either  output  bytes  that  are improperly encoded for the current locale, or null
      input bytes when the -z option is not given.

因此日志文件可能已损坏,或者某些应用程序可能已将非文本字节写入该文件。

另请参阅:

相关内容