Solved

FILE COMMAND

Posted on 2006-07-02
3
337 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
reinstall 1 77
Linux : understanding ifcfg-*** files  from directory  #/etc/sysconfig/network-scripts 11 98
dot directory in FreeBSD??? 4 79
cron job says it ran, no results 25 118
Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

786 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