Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
Mercy Corps

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents

· Introduction to Operating Systems
· Linux Basics
· Working with the System
· Shells and Utilities
· Editing Files
· Basic Administration
· The Operating System
· The X Windowing System
· The Computer Itself
· Networking
· System Monitoring
· Solving Problems
· Security
· Installing and Upgrading
· Linux and Windows

Glossary
MoreInfo
Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
FAQ
Copyright Info
Terms of Use
Privacy Info
Disclaimer
WorkBoard
Thanks
Donations
Advertising
Masthead / Impressum
Your Account

Communication
Feedback
Forums
Private Messages
Surveys

Features
HOWTOs
News Archive
Submit News
Topics
User Articles
Web Links

Google
Google


The Web
linux-tutorial.info

Who's Online
There are currently, 180 guest(s) and 0 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here

  

magic



DESCRIPTION

       This manual page documents the format of the magic file as
       used by the file(1) command, version 4.03.  The file  com­
       mand  identifies  the  type  of  a file using, among other
       tests, a test for whether the file begins with  a  certain
       magic  number.   The  file /usr/share/misc/magic specifies
       what magic numbers are to be tested for, what  message  to
       print  if  a  particular  magic number is found, and addi­
       tional information to extract from the file.

       Each line of the file specifies a test to be performed.  A
       test  compares the data starting at a particular offset in
       the file with a 1-byte, 2-byte, or 4-byte numeric value or
       a  string.   If  the  test succeeds, a message is printed.
       The line consists of the following fields:

       offset   A number specifying the offset,  in  bytes,  into
                the file of the data which is to be tested.

       type     The  type of the data to be tested.  The possible
                values are:

                byte     A one-byte value.

                short    A two-byte value (on  most  systems)  in
                         this machine's native byte order.

                long     A  four-byte  value (on most systems) in
                         this machine's native byte order.

                string   A string  of  bytes.   The  string  type
                         specification can be optionally followed
                         by /[Bbc]*.   The  ``B''  flag  compacts
                         whitespace  in  the  target,  which must
                         contain at least one whitespace  charac­
                         ter.   If  the  magic  has n consecutive
                         blanks, the target needs at least n con­
                         secutive  blanks  to  match.   The ``b''
                         flag treats every blank in the target as
                         an  optional  blank.   Finally the ``c''
                         flag, specifies case insensitive  match­
                         ing:  lowercase  characters in the magic
                         match both lower and upper case  charac­
                         ters  in  the targer, whereas upper case
                         characters  in  the  magic,  only   much
                         uppercase characters in the target.

                date     A  four-byte value interpreted as a UNIX
                         date.

                ldate    A four-byte value interpreted as a UNIX-
                         style  date,  but  interpreted  as local

                lelong   A  four-byte  value (on most systems) in
                         little-endian byte order.

                ledate   A four-byte value (on most  systems)  in
                         little-endian byte order, interpreted as
                         a UNIX date.

                leldate  A four-byte value (on most  systems)  in
                         little-endian byte order, interpreted as
                         a UNIX-style date,  but  interpreted  as
                         local time rather than UTC.

       The  numeric  types  may optionally be followed by & and a
       numeric value, to specify that the value is to  be  AND'ed
       with  the  numeric  value before any comparisons are done.
       Prepending a u to the type indicates that ordered  compar­
       isons should be unsigned.

       test   The  value  to  be compared with the value from the
              file.  If the type is numeric, this value is speci­
              fied  in C form; if it is a string, it is specified
              as a C string  with  the  usual  escapes  permitted
              (e.g. \n for new-line).

              Numeric values may be preceded by a character indi­
              cating the operation to be performed.  It may be =,
              to  specify that the value from the file must equal
              the specified value, <, to specify that  the  value
              from  the  file  must  be  less  than the specified
              value, >, to specify that the value from  the  file
              must  be  greater  than  the specified value, &, to
              specify that the value from the file must have  set
              all  of  the  bits  that  are  set in the specified
              value, ^, to specify that the value from  the  file
              must have clear any of the bits that are set in the
              specified value, or x, to specify  that  any  value
              will  match.   If  the  character is omitted, it is
              assumed to be =.

              Numeric values are specified in C form; e.g.  13 is
              decimal, 013 is octal, and 0x13 is hexadecimal.

              For  string  values,  the byte string from the file
              must match the specified byte string.   The  opera­
              tors  =,  <  and  >  (but  not &) can be applied to
              strings.  The length used for matching is  that  of
              the  string argument in the magic file.  This means
              that a line can match any string, and then  presum­
              ably  print  that string, by doing >\0 (because all
              strings are greater than the null string).

       closely  preceding it in the magic file.  If the test on a
       line at level n succeeds, the tests specified in  all  the
       subsequent  lines at level n+1 are performed, and the mes­
       sages printed if the tests  succeed.   The  next  line  at
       level n terminates this.  If the first character following
       the last > is a ( then the string after the parenthesis is
       interpreted  as  an  indirect offset.  That means that the
       number after the parenthesis is used as an offset  in  the
       file.  The value at that offset is read, and is used again
       as an offset in the file.  Indirect  offsets  are  of  the
       form:  ((x[.[bslBSL]][+-][y]).   The value of x is used as
       an offset in the file. A byte, short or long  is  read  at
       that offset depending on the [bslBSL] type specifier.  The
       capitalized types interpret the number  as  a  big  endian
       value,  whereas  the  small  letter versions interpret the
       number as a little endian value.  To that number the value
       of  y  is added and the result is used as an offset in the
       file.  The default type if one is not specified is long.

       Sometimes you do not know the exact offset as this depends
       on  the  length  of  preceding fields.  You can specify an
       offset relative to the end of the last uplevel  field  (of
       course  this  may  only  be  done for sublevel tests, i.e.
       test beginning with > ).  Such a relative offset is speci­
       fied using & as a prefix to the offset.


BUGS

       The formats long, belong, lelong, short, beshort, leshort,
       date, bedate, and  ledate  are  system-dependent;  perhaps
       they  should  be  specified  as a number of bytes (2B, 4B,
       etc), since the files being recognized typically come from
       a system on which the lengths are invariant.

       There  is (currently) no support for specified-endian data
       to be used in indirect offsets.


SEE ALSO

       file(1) - the command that reads this file.

                          Public Domain                  MAGIC(5)
  

Looking for a "printer friendly" version?


Login
Nickname

Password

Security Code
Security Code
Type Security Code


Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!


Amazon Wish List

Did You Know?
The Linux Tutorial welcomes your suggestions and ideas.


Friends



Tell a Friend About Us

Bookmark and Share



Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.04 Seconds