?
Solved

FILE COMMAND

Posted on 2006-07-02
3
Medium Priority
?
341 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 150 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

765 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