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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Binary txt file received when i use uuencode to send txt file as attachment ash22 UNIX for Dummies Questions & Answers 2 04-24-2008 08:03 PM
compiled binary file gives "cannot execute binary file" scgupta SUN Solaris 0 07-13-2006 01:59 AM
binary file markms UNIX for Dummies Questions & Answers 1 04-07-2006 09:40 AM
binary file ramneek UNIX for Dummies Questions & Answers 1 09-13-2005 05:02 PM
Binary File Transfer DPAI High Level Programming 2 03-04-2002 03:12 PM

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 05-12-2004
scmay scmay is offline
Registered User
  
 

Join Date: Apr 2004
Location: Melbourne
Posts: 15
How do I test whether that is a binary file?

Hi, I tried locating my book for the keyword to test whether the file is a binary file but I can't find it under test.

Anyone any idea what the key letter is ?
  #2 (permalink)  
Old 05-12-2004
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
in solairs you can use the command file.
  #3 (permalink)  
Old 05-12-2004
scmay scmay is offline
Registered User
  
 

Join Date: Apr 2004
Location: Melbourne
Posts: 15
re:

opps. forgot to mention I am using Bourne Shell.sorry!
  #4 (permalink)  
Old 05-12-2004
myscsa2004 myscsa2004 is offline
Registered User
  
 

Join Date: Mar 2004
Posts: 11
Did you try:

$ type -type <file>

I know it will say file / builtin / hashed, etc.. I'm not sure about binary, that's bash too, i never tried it in sh...just a thought
  #5 (permalink)  
Old 05-12-2004
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,748
If you mean binary in the unix sense (no carriage control)
use the command "file", and it is not some type of ELF or a.out format file:

file filename for a "binary" file
returns

filename: data

If file finds carriage control (newlines) and printable ascii characters:

filename: ascii data

Otherwise, it uses a magic number to figure out what type of file you are dealing with.

On PC's under DOS or Windows, binary files do not have exactly the same meaning they do for unix, nor does the file system handle them the same way. The EOF marker for text files is control-Z, ASCII 26. Binary files keep the length of the file in the FAT, and treat ascii 26 as an ordinary character. Unix does not do this. There is no EOF marker in the file. Binary and ascii files are handled the same way by the file system. It keeps track of where the file ends.
  #6 (permalink)  
Old 06-03-2004
mbb mbb is offline
Registered User
  
 

Join Date: Aug 2001
Location: UK
Posts: 104
The file command will tell you the type of file - most of the time!

Because it is using the contents of the file it can sometimes get the answer wrong.

A different way of looking for a file type is to use the find command with the -type conjunction.

Also certain file types have a disctinct 'marker' in the data. e.g. some TIF files will have 0x490x49 as the first two bytes. Although you could write a program to look for this TIF marker, it would be very easy to fool it with a hoax file. And now, I hope you will appreciate the limitations with the file command.
  #7 (permalink)  
Old 06-03-2004
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,748
mbb -

In unix a file is a bag of bytes. Period. There is no such thing as a binary file or a text file, except perhaps in terms of how you retreive data from it, or which magic number the file has. All I/O uses base modules like read. The higher-level i/o modules call read, then play with the data in the buffer and return chunks of it.


Windows programmers insist on "binary". When they come to linux it takes them along time to figure out what the file system actually does.
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 04:31 PM.


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