Monday, November 23, 2009  
Google
Web pcquest.com

CIOL Network sites

Search by Issue | Sitemap | Advanced Search

• For most updated version of DQ TOP 20 issue, visit dqindia.com • Ad : Play and Plug ERP by IBM


 
    Enterprise Solutions
    Hands On
    ITstrategy

    Developer

    Tech Forum

    SMB Forum

    Trends

    Shootout

    Reviews
    Editorials
    Linux and Open Source
    Technology
    Extraedge

    IT Careers

    Vertical Focus

Subscribe to Print magazine.


now!


Newsletter

 

Home > > Linux Hands On > File Associations in Linux


File Associations in Linux




Continued from Page 2

Remember that you’ve to be in root to register file formats.

Let’s start with a simple example of text files. Let’s say we want to register all the files with the TXT extension as binary files, to be interpreted by the editor vi (or any other editor for that matter).

To do this, simply type at the prompt (in the rest of this article, lines beginning with % are typed at the prompt):

% cd /proc/sys/fs/binfmt_misc
% echo ":text:E::txt::/bin/vi:" > register

That’s all! The first field—text—is the name that we give to this format. "E" indicates that recognition will be by file extension. The next field is empty because we’re not using magic numbers in this case. The extension is TXT, without the dot. And finally, "/bin/vi" is the program which will be invoked when you "execute" a text file.

Now you’ll find a new file in /proc/sys/fs/binfmt_misc called "text". This happens for every binary format registered. That file will have something like:

enabled
interpreter /bin/vi
extension .txt

To test your new file format, make the file, say, foo.txt, executable with "% chmod +x foo.txt".

Then at the prompt type "% ./foo.txt". This should bring up foo.txt in vi.

An example with magic numbers

Now let’s have some more fun, and register the JPEG image format, so that we can view one in XV just by making it executable, and typing it’s name at the prompt. We’ll use magic numbers this time. The magic number for JPEG images is ffd8 (in hexadecimal). Registering it is easy:

% cd /proc/sys/fs/binfmt_misc
% echo ":jpeg_img:M::\xff\xd8::/usr/X11R6/bin/xv:" > register

Now you should have a new file called "jpeg_img" in /proc/sys/binfmt_misc, which should look like:

enabled
interpreter /usr/X11R6/bin/xv
offset 0
magic ffd8

To get back to where it all began, Java classes, you can register that too. But I won’t explain that here. It’s done in the kernel documentation. Look at /usr/src/linux/Documentation/java.txt.

Next time we’ll see how to write a small wrapper, a shell script to tweak things a bit before actually calling the interpreter.


Page(s)   1   2   3   

End of the article

PC Problems? Get a solution in 24 hours. Ask Tech Expert

Related CIOL links   External links  

--None--

 

none



Read Previous Linux Hands On...

   




Untitled Document



ZTE:Leading CDMA Technology






Previous Stories

MagicPoint

Backup in Linux

A Transparent Proxy With Squid

Message boards

Discuss this and many other IT topics at the
CIOL message board



   
 

 
 

Magazine Subscription | RQS | Contact Us | Team PCQuest | Advertising - Print | jobs@cybermedia