原因

file未安装或者PATH变量没有包含file命令的路径

解决方法

Linux中如何解决命令没找到的问题 bash: command not found ?

查看PATH变量是否包含file命令的路径

file命令的路径,有3种方法

[root@yunkai ~]# which file
/usr/bin/file
[root@yunkai ~]# type -a file
file is /usr/bin/file
[root@yunkai ~]# command -v file
/usr/bin/file
[root@yunkai ~]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

路径 /usr/bin在PATH变量中。

安装file命令

在Debian / Ubuntu中安装file命令

sudo apt info file
sudo apt update && sudo apt upgrade
sudo apt install file

在CentOS中安装file命令

yum install file
file: command not found

描述

执行file /usr/local/bin/sqsh命令是,提示 bash: file: command not found.

如何使用file命令

查看压缩包内的文件

file -z file.zip

查看文件类型

[root@yunkai ~]# file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
[root@yunkai ~]# file /bin/date
/bin/date: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

### 输出时不包含文件名
[root@yunkai ~]# file -b /bin/date
ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

其他未找到的命令也可以使用此方法进行解决。

日期:2019-04-29 03:17:51 来源:oir作者:oir