Monday, October 17, 2011

Unix interview questions

Q  . What is a "Sha-bang" in *nix?
Ans.
The ShaBang (#!) or sharp(#)bang(!), at the beginning of a *nix script tells the system that this file is a set of command(s) to be provided to the mentioned command interpreter.The #! is
actually a two-byte magic number, a special marker that designates a file type.Sha-bang is followed by a path name to the program that interprets the commands in
the script.



------------------------------------------------------------------



Q  .  How "file" command works?
Ans. 
The file command identifies the type of a file using,among other tests, a test for whether the file begins with a certain magic number. The /etc/magic file
specifies what magic numbers are to be tested for, what message to print if a particular magic number is found, and additional information to extract from the file.


Each line of the file specifies a test to perform. 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.

By default, file will try to use the localized magic file /usr/lib/locale/locale/LC_MESSAGES/magic, if it exists, to identify files that have a magic number.

If a localized magic file does not exist, file will utilize /etc/magic.

Source: man magic

No comments:

Post a Comment