Unix 'file' 命令需要多长时间?

16 unix shell

当您将文本文件传递给 Unixfile命令时,它可能会告诉您类似以下内容:

input.txt: UTF-8 Unicode English text, with very long lines
Run Code Online (Sandbox Code Playgroud)

有人能告诉我一行必须包含的最少字符数才能被视为很长吗?手册页对此没有任何说明,我不想搜索源代码。如果有人能告诉我如何将这个问题放入 Google 查询中,该查询不会返回 10 亿个结果,几乎所有结果都无关紧要,我也会很高兴。

Bas*_*Ben 23

从Ubuntu 上ascmagic.c文件源包中:

#include "names.h"

#define MAXLINELEN 300  /* longest sane line length */
#define ISSPC(x) ((x) == ' ' || (x) == '\t' || (x) == '\r' || (x) == '\n' \
          || (x) == 0x85 || (x) == '\f')
Run Code Online (Sandbox Code Playgroud)

似乎一行需要超过 300 个字符才能被视为“很长”。


Emi*_*röm 7

根据源代码中 ascmagic.c 的第 52 行和第 214-215 行,超过 300 个字符。

可以在此处找到源代码(从 Debian 手册页获取的链接file):ftp : //ftp.astron.com/pub/file/


Den*_*son 7

蛮力(加上这是一个程序,对吧?所以它使它与编程相关?):

$ for i in {1..301}; do printf "%${i}s" "." | file - | grep very && echo $i; done
/dev/stdin: very short file (no magic)
1
/dev/stdin: ASCII text, with very long lines, with no line terminators
301
Run Code Online (Sandbox Code Playgroud)