如何在没有确认的情况下减少打开的二进制文件?

gio*_*oni 4 unix command-line less

我有几个包含几个字节的日志文件,这些字节不是可显示的字符(由于请求上的二进制签名)。

每次我打开它们时都会被问到:

$ less /var/log/file.log       
"/var/log/file.log" may be a binary file.  See it anyway? 
Run Code Online (Sandbox Code Playgroud)

如何使用命令行选项或配置减少跳过此步骤?

小智 7

使用-f选项:

-f or --force
              Forces non-regular files to be opened.  (A non-regular file is a directory or
              a device special file.)  Also suppresses the warning message  when  a  binary
              file  is  opened.   By  default,  less will refuse to open non-regular files.
              Note that some operating systems will not allow directories to be read,  even
              if -f is set.
Run Code Online (Sandbox Code Playgroud)

您可以将此选项添加到LESS.bashrc 中的环境变量中,less以默认使用.bashrc 运行-f

export LESS='-f'
Run Code Online (Sandbox Code Playgroud)