4

使用file命令识别磁盘文件格式

 3 years ago
source link: https://www.lujun9972.win/blog/2018/09/26/%E4%BD%BF%E7%94%A8file%E5%91%BD%E4%BB%A4%E8%AF%86%E5%88%AB%E7%A3%81%E7%9B%98%E6%96%87%E4%BB%B6%E6%A0%BC%E5%BC%8F/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

使用file命令识别磁盘文件格式

file命令常用来检测文件格式,考虑到linux中一切皆为文件,因此用file命令检测磁盘文件格式似乎也是顺理成章的事情了。

但是你如果直接执行

sudo file /dev/sda1

你会发现file命令只会告诉你这是个块特殊文件

/dev/sda1: block special (8/1)

这是因为由于读特殊文件将可能导致不可知后果,因此默认情况下,file只会去检查那些 stat 报告为正常文件的文件的类型.

但你可以通过 -s 选项来让file命令读取块特殊文件和字符特殊文件,这可以从原始磁盘分区中获取文件系统类型:

sudo file -s /dev/sda
sudo file -s /dev/sda1
/dev/sda: DOS/MBR boot sector
/dev/sda1: Linux/i386 swap file (new style), version 1 (4K pages), size 2097151 pages, no label, UUID=f1060c0a-bd02-4547-98d4-af3e1685e513

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK