Solved

FILE COMMAND

Posted on 2006-07-02
3
334 Views
Last Modified: 2010-04-21
Hi
I am new to UNIX.
I want to clarify one thing--
an eg is given as-- $ file monday reports
and the book states monday : text file
                             reports : directory.. How can we know tht its a text file?and directory?
and same as another  $ file calc.c proj newdata
here calc.c is C prog and proj - executable file and newdata is empty file.

So how to classify them ..On what basis are they classified?..
0
Comment
Question by:m_razesh
3 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17026468
the file command relies on the /etc/magic file which contains patterns to identify a files content

> How can we know tht its a text file?and directory?
not with the file command, obviously (see its name:-)
use ls -l

> here calc.c is C prog and proj - executable file and newdata is empty file.
what do you mean?
If a file is executable (see ls -l) or not doesn't matter the file command.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17028041
man magic
0
 
LVL 1

Accepted Solution

by:
shmukler earned 50 total points
ID: 17038848
like ahoffmann wrote the file works as following (sources for BSD and Linux implementation are pretty clear and will tell how specifically it works on your system if you are using open source version).

also, to a new Unix'ist I suggest to always try:

$whatis file
(or it could be #whatis socket)

to see all relevant installed manual pages

searching for file returns lots of results. we know that we need file(1) and stat(2)

first file sees whether file is emply, then it could be anything.

if file is not next, file will look for magic number - a signature of sorts. the list of signatures could be in /usr/share/magic or /etc/magic or elsewhere depending on your environment. it would usually be made up from collection of smaller files

if any of the magic numbers matches the content. (some systems can recognize even bootsectors and files from foreign OSes, others only supported executable formats)

next it looks whether it includes characters other than ASCII and some command characters such as new line etc.

If it's ASCII file, then it's probably text.

If nothing matches then we say that it's binary data, as this is a very wide term. :)

$man file               on your system will tell specifics about your version of file(1)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now