LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-14-2006, 04:21 PM   #1
vijraj
LQ Newbie
 
Registered: Oct 2006
Posts: 14

Rep: Reputation: 0
file types


Hi Everyone!

I am working on a c program which displays all the directories and files under each directory.
I want to know what kind of file each is. Like, is the file an ascii text file or english text or a c file.
if it is an executable, is it an binary file or a shell script.
I was told to look inside the file to achieve this.How should I do this.Man pages are difficult to understand and quite confusing.Any help is appreciated.
Thanks in advance.
 
Old 11-14-2006, 04:34 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
check out the functionality from the standard libmagic http://www.die.net/doc/linux/man/man3/libmagic.3.html
 
Old 11-14-2006, 07:25 PM   #3
vijraj
LQ Newbie
 
Registered: Oct 2006
Posts: 14

Original Poster
Rep: Reputation: 0
Thankyou,acid_kewpie!
 
Old 11-14-2006, 08:07 PM   #4
vijraj
LQ Newbie
 
Registered: Oct 2006
Posts: 14

Original Poster
Rep: Reputation: 0
Hi acid_kewpie!

Can u give me an example of how to read a file for bytes and then decide what it is.I am all confused.
Like, stat returned and says it is a regular file is a regular file.
So from now what should I do?
Thanks for ur help.
 
Old 11-15-2006, 02:37 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
i've not used libmagic to be honest, it's just the c / c++ bindings to the same backend that the "file" program uses.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
file server types Hondro Linux - Software 3 07-12-2006 09:15 AM
File System types Soup Erman Linux - Newbie 6 05-13-2006 02:27 AM
How to remove certain types of file? heislyc Linux - General 5 02-17-2006 12:21 PM
changing file types buffed317 Linux - General 1 07-21-2004 09:26 PM
file types jclark00001 Linux - Newbie 2 02-17-2003 03:07 PM


All times are GMT -5. The time now is 02:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration