The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Type I and Type II Errors - The Heart of Event Processing iBot Complex Event Processing RSS News 0 12-05-2007 06:50 PM
array type has incomplete element type jaganadh High Level Programming 1 07-24-2007 03:54 AM
Determining type of file JWilliams UNIX for Dummies Questions & Answers 2 04-20-2007 03:14 AM
Human readable type vs MIME type detection using file spauldingsmails Shell Programming and Scripting 0 03-22-2007 12:43 AM
Identify type of file DebianJ Shell Programming and Scripting 1 11-17-2005 11:55 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-14-2006
vijlak vijlak is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 23
file type

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.
Is there any unix utility to do this?what function can I use to achive this.Thank you for any kind of help .
  #2 (permalink)  
Old 11-14-2006
!_30's Avatar
!_30 !_30 is offline
Registered User
  
 

Join Date: Sep 2006
Location: Romania
Posts: 37
Hey dude ,

You can just use file <file> command dude .

you can use it from C , with system(" file <file>");

Let's say , you got some files :

ok.c exe ..

you make the code , with system("file <file>"); or you use file <file> command withing shell script :

you should get something like :

Code:
exe: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.0, dynamically linked (uses shared libs), not stripped
file.c : ex.c: ASCII C program text
  #3 (permalink)  
Old 11-14-2006
vijlak vijlak is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 23
Thanks

Hi !_30!

Thank you! Ur suggetion was very much helpful.
But I just want the message like ascii text or english text.How can I do that?
Is the returned value a string or what?
Can u give me a more detailed example.

ps:Thanks.I think u r really smart.U reply to most of my questions.
Thanks anyway.
  #4 (permalink)  
Old 11-14-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,929
General questions about the command 'file' are best answered by looking at 'man file'. Yes, it prints human-readable strings.
  #5 (permalink)  
Old 11-14-2006
!_30's Avatar
!_30 !_30 is offline
Registered User
  
 

Join Date: Sep 2006
Location: Romania
Posts: 37
Like , it was saied , all you can find it's in man file

You can see there a lot of option's .. No the result is not a string , but I can say to you that is inspired from :

/usr/share/misc/file/magic.mime


If you want just a part of that message to be shown , you can just copy a part of it with ( STRNCPY(string,initial_string+x,y) ) from it ..

  #6 (permalink)  
Old 11-14-2006
vijlak vijlak is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 23
Thank you, everyone.
Pardon me for my dumb questions.
Can u please tell me whether the filename specified in system("file <file>") should be a constant or can it be a variable too?
Because, the file name is in a variable dirt and it changes for every iteration in the loop.
Thanks again.
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0