前言

file命令可以获取多种文件类型,包括文本文件、脚本文件、源码文件、多媒体文件(音频视频)等。file是通过查看文件的头部内容,来获取文件的类型,而不像Window那样是通过扩展名来确定文件类型的。

命令用法

-z 获取压缩文件的类型(不能是用tar打包过的),比如gzip、zip等压缩过的

-L 获取软链所指向的文件的类型

-f 指定文件列表参数,获取该列表里面的所有文件的类型

常见用法

file FileName

 1: [root@master lianxi]# file test 
 2: test: ASCII text
 1: [root@master lianxi]# > 1
 2: [root@master lianxi]# file 1
 3: 1: empty

file使用通配符,获取多个文件的类型

file *.lua (以.lua结尾的文件)

 1: [root@master lianxi]# file *.lua
 2: 2.lua: ASCII text
 3: 3.lua: ASCII text
 4: 4.lua: ASCII text

数据文件类型(某些程序专用的数据格式)

 1: [root@master lianxi]# file /var/log/lastlog 
 2: /var/log/lastlog: data

Python脚本文件

 1: [root@master lianxi]# file print.py 
 2: print.py: a /bin/python  script text executable

-z 参数,可以获取用gzip、zip压缩过的文件的类型

 1: [root@master lianxi]# gzip print.py 
 2: [root@master lianxi]# ls print.py.gz 
 3: print.py.gz
 4: [root@master lianxi]# zip -r print.py.zip print.py.gz 
 5: adding: print.py.gz (stored 0%)
 6: [root@master lianxi]# ls print.py.zip 
 7: print.py.zip
 8: [root@master lianxi]# file print.py.*
 9: print.py.gz:  gzip compressed data, was "print.py", from Unix, last modified: Fri Jun 14 20:48:14 2013
 10: print.py.zip: Zip archive data, at least v1.0 to extract

-L 获取软链指向的文件的类型。默认是返回软链本身类型

 1: [root@master lianxi]# ln -s test test.soft
 2: [root@master lianxi]# ls -l test*
 3: -rw-r--r-- 1 root root 25 Jun 14 20:09 test
 4: lrwxrwxrwx 1 root root  4 Jun 14 20:51 test.soft -> test
 5: [root@master lianxi]# file test.soft 
 6: test.soft: symbolic link to `test'
 7: [root@master lianxi]# file -L test.soft 
 8: test.soft: ASCII text
 9: [root@master lianxi]# 

-f 获取一个文件名列表的所有文件的类型。1)注意路径是否正确 2)每行一个文件名

 1: [root@master dir]# ls
 2: 1  2  3
 3: [root@master dir]# ls > a
 4: [root@master dir]# cat a
 5: 1
 6: 2
 7: 3
 8: a
 9: [root@master dir]# file -f a
 10: 1: ASCII text
 11: 2: ASCII text
 12: 3: empty
 13: a: ASCII text

特殊说明

1)在Window中,Windows系统对文件系统文件的标识是通过其扩展名。但是Windows上的程序自己也可以通过文件内容来判断文件内容类型

2)file 是通过读取文件头部内容,来获取文件类型,比如BASH脚本文件以#!/bin/bash 或Python脚本以#!/bin/python等,file读取其头部信息判断类型。

3)file可以辨识的文件类型很多,文本文件、脚本文件、数据文件、多媒体文件等。

总结

file命令,获取文件类型。

linux命令详解:file命令的更多相关文章

  1. (转)Linux命令详解-file

    Linux命令详解-file 原文:https://www.cnblogs.com/Dodge/p/4278306.html file命令用来识别文件类型,也可用来辨别一些文件的编码格式.它是通过查看 ...

  2. linux shell 脚本攻略学习14--head命令详解,tail命令详解

    当要查看上千行的大文件时,我们可不会用cat命令把整个文件内容给打印出来,相反,我们可能只需要看文件的一小部分地内容(例如文件的前十行和后十行),我们也有可能需要打印出来前n行或后n行,也有可能打印除 ...

  3. linux shell 脚本攻略学习13--file命令详解,diff命令详解

    一.file命令详解 find命令可以通过查看文件内容来找出特定类型的文件,在UNIX/ Linux系统中,文件类型并不是由文件扩展名来决定的(windows中却正是这么做的),file命令的目的是从 ...

  4. linux shell 脚本攻略学习 -- head命令详解, tail命令详解

    当要查看上千行的大文件时,我们可不会用cat命令把整个文件内容给打印出来,相反,我们可能只需要看文件的一小部分地内容(例如文件的前十行和后十行),我们也有可能需要打印出来前n行或后n行,也有可能打印除 ...

  5. [转]dd命令、cp命令详解+dd命令、cp命令对比 ---delong

    出处:http://blog.csdn.net/sun_app/article/details/18263299 1.dd命令详解 1)中文man手册dd的解释 NAME       dd - 转换和 ...

  6. Linux命令详解-file

    file命令用来识别文件类型,也可用来辨别一些文件的编码格式.它是通过查看文件的头部信息来获取文件类型,而不是像Windows通过扩展名来确定文件类型的. 1.命令格式: file [ -bchikL ...

  7. linux命令大全之watch命令详解(监测命令运行结果)

    watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行.在Linux下,watch是周期性的执行下个 ...

  8. linux系统find命令详解+xargs命令 、exec命令

    find 作用:查找文件 1.name: 指定文件名 例子1. 找到以du结尾的文件 ╭─root@localhost.localdomain ~ ╰─➤ find / -name "*du ...

  9. linux命令详解:df命令

    转:http://www.cnblogs.com/lwgdream/p/3413579.html 前言 df命令用来查看系统的space和inode使用情况,也是常用命令之一 使用说明 -a 显示所有 ...

  10. tar 命令详解 / xz 命令

    ]# tar [-cxtzjvfpPN] 文件与目录 ....参数:-c :建立一个压缩文件的参数指令(create 的意思):-x :解开一个压缩文件的参数指令!-t :查看 tarfile 里面的 ...

随机推荐

  1. d3 使用随机数据生成条形图

    ).map(function(){ ,)(),); }) // 返回 [27.2, 12.9, 12.2, 6.8, 9.4, 7.1, 17.5, 30, 16.6, 24.3, 19, 16.6, ...

  2. 最新版浏览器报错net::ERR_INSECURE_RESPONSE原因

    访问的网址与接口请求的域名不一致,新版的chrome浏览器出于安全的考虑会将请求进行拦截,并报错net::ERR_INSECURE_RESPONSE

  3. linux 时间模块 一

    作者:云天明链接:https://www.zhihu.com/question/50764115/answer/122613742来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...

  4. hdu 4510(模拟)

    小Q系列故事——为什么时光不能倒流 Time Limit: 300/100 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)T ...

  5. 快速上手 Echarts

    最近使用到了 百度的 Echarts 数据可视化工具,这里简单介绍如何快速上手. 一.下载 这里选择目前最新版本,4.2.1 地址:https://github.com/apache/incubato ...

  6. Careercup | Chapter 5

    5.1 You are given two 32-bit numbers, N andM, and two bit positions, i and j. Write a method to inse ...

  7. Ampzz 2011 Cross Spider 计算几何

    原题链接:http://codeforces.com/gym/100523/attachments/download/2798/20142015-ct-s02e07-codeforces-traini ...

  8. bzoj 1552: [Cerc2007]robotic sort

    1552: [Cerc2007]robotic sort Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1198  Solved: 457[Submit] ...

  9. CF997D

    分析: 假设在第一个树上我们有一个长度为x的环,在第二树上我们有一个长度为y的环,那么可以在叉积树上构造出$\binom{x+y}{x}$个长度为x+y的环 问题的关键就变成了如何统计出在一个树上的长 ...

  10. springboot idea激活指定profile

    多Profile文件 配置文件编写的时,可以是application-{profile}.properties/yml,默认使用application.properties的配置: 激活指定profi ...