程式扎記: [Linux 文章收集] Linux / UNIX: Determine File Type

標籤

2016年3月2日 星期三

[Linux 文章收集] Linux / UNIX: Determine File Type

Source From Here
Question
How do I determine the file type under UNIX or Linux like operating systems?

How-To
You need to use the file command to determine file type. File command tests each argument in an attempt to classify it. There are three sets of tests, performed in this order: filesystem tests, magic number tests, and language tests. The first test that succeeds causes the file type to be printed on screen.

file Command Examples
First example:
# file /etc/passwd
/etc/passwd: ASCII text

Another example:
# file /home/voffice/letter.doc
... : Microsoft Office Document

Or let's test C source file:
# file wait.c
wait.c: C source, ASCII text

How about binary file:
# file $(which pwd)
/usr/bin/pwd: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=ceaf8a5790e50ef5b28390951a052152c1caa9db, stripped

Even the device files:
# file /dev/sda{1,2,3}
/dev/sda1: block special
/dev/sda2: block special
/dev/sda3: block special


沒有留言:

張貼留言

網誌存檔

關於我自己

我的相片
Where there is a will, there is a way!