[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

FILE COMMAND

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
m_razesh
Asked:
m_razesh
1 Solution
 
ahoffmannCommented:
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
 
TintinCommented:
man magic
0
 
shmuklerCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now