日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

linux命令详解:file命令

發布時間:2023/12/19 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux命令详解:file命令 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

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命令,獲取文件類型。

轉載于:https://www.cnblogs.com/xujie2013/p/3408516.html

總結

以上是生活随笔為你收集整理的linux命令详解:file命令的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。