该研究指南在确定文件类型的命令方面是否错误?


10

学习指南LPIC-1培训和准备指南(Ghori Asghar,ISBN 978-1-7750621-0-3)包含以下问题...

以下哪个命令可用于确定文件类型?

  • (一种) file
  • (B) type
  • (C) filetype
  • (D) what

……并声称答案是:“(B)type”。

但是“(A)file”不是正确的答案吗?

我开始怀疑整本书。


11
我不得不说,一本书的开头是“考试基于RHEL和Debian,所以让我们使用CentOS和Ubuntu”不会激发信心!
史蒂芬·基特

您应该联系作者,并把错误通知他。
dr_18年

Answers:


10

是的,看来您的书是错误的。

file命令告诉它是哪种文件。在手册文件中:“文件-确定文件类型”。
一些例子:

$  file /usr/bin/file
/usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=ecc4d67cf433d0682a5b7f3a08befc45e7d18057, stripped
$ file activemq-all-5.15.0.jar
activemq-all-5.15.0.jar: Java archive data (JAR)

type命令用于告诉命令是内置的还是外部的:

$ type file
file is /usr/bin/file
$ type type
type is a shell builtin

6
type是大多数shell的内置函数,它告诉我们可以执行的操作是什么(内置函数,别名,函数,可执行文件等)。在您的情况下,这就是说没有test.sh可以执行的(在PATH中,或者作为内置/函数/别名等)。
大师

你是绝对正确的。我从来不知道 不会改变答案应该是file。我将更新我的答案。
MikaelKjær18年

谢谢您的回答,我很高兴我盗版了《 lol
Linux Lover》,

2

文件类型通常由确定file。其man状态:

文件—确定文件类型

但是您也可以在一定程度上使用type。比较以下两个清单的内容:

  • script.pl,一个Perl脚本
  • not_a_script,一个空文件

这是脚本的一个:

$ ls
script.pl
$ file script.pl 
script.pl: Perl script text executable
$ type script.pl
bash: type: script.pl: not found
$ type ./script.pl 
./script.pl is ./script.pl

这是一个空文件:

$ ls not_a_script 
not_a_script
$ file not_a_script 
not_a_script: empty
$ type not_a_script
bash: type: not_a_script: not found
$ type ./not_a_script
bash: type: ./not_a_script: not found

如您所见,type可以确定文件是否可执行。那是“文件类型的确定”吗?好吧...与file提供的方式不同。typeBash的男人对buildin 的描述如下:

输入[-aftpP]名称[名称...]

如果没有选项,请指明如果用作命令名称,每个名称将如何解释。

在我看来file,书中问题的正确答案应该是我认为的,因为这就是它man所说的,这就是通过测试的意思。换句话说,我的首选是file

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.