How do I test whether that is a binary file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do I test whether that is a binary file?
# 1  
Old 05-12-2004
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 ?Smilie
# 2  
Old 05-12-2004
in solairs you can use the command file.
# 3  
Old 05-12-2004
re:

opps. forgot to mention I am using Bourne Shell.sorry!
# 4  
Old 05-12-2004
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  
Old 05-12-2004
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  
Old 06-03-2004
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  
Old 06-03-2004
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

2. UNIX for Dummies Questions & Answers

[AIX] Binary file warning for text file.

Hello guys, We had to move from a DC to another, and we are now facing an "issue" with some text files. Looks like that some of our log files are set as binary: file TuxConnectorURA.20121012 TuxConnectorURA.20121012: data or International Language text less TuxConnectorURA.20121012... (2 Replies)
Discussion started by: EnioMarques
2 Replies

3. Shell Programming and Scripting

Output redirection of c binary file to a file in shell script is failing

I am struck up with a problem and that is with output redirection. I used all the ways for the redirection of the output of c binary to a file, still it is failing. Here are the different ways which I have used: ./a.out | tee -a /root/tmp.txt 2>&1 ./a.out | tee -a /root/tmp.txt 1>&1 ./a.out |... (2 Replies)
Discussion started by: Maya29988
2 Replies

4. UNIX for Advanced & Expert Users

How to copy a binary file while the file is being written to by another process

Hello, Can I copy a binary file while the file is being written to by another process? Another process (program) “P1” creates and opens (for writing) binary file “ABC” on local disk. Process P1 continuously write into ABC file every couple of seconds, adding 512-byte blocks of data. ABC file... (1 Reply)
Discussion started by: mbuki
1 Replies

5. UNIX for Dummies Questions & Answers

Pipe binary file matches grep results to file

I am using grep to match a pattern, but the output is strange. $ grep -r -o "pattern" * Gives me: Binary file foo1 matches Binary file foo2 matches Binary file foo3 matches To find the lines before/after, I then have to use the following on each file: $ strings foo1 | grep -A1 -B1... (0 Replies)
Discussion started by: chipperuga
0 Replies

6. Shell Programming and Scripting

To log binary file output to a txt file

Hi, I wrote a small script whose function is to execute the postemsg provided if the threshold breaches. I want to log this postemsg messages to a log file. But I am not able to do. Can someone throw some light on how to log the output of this. I am pasting a snippet of that code. ... (2 Replies)
Discussion started by: dbashyam
2 Replies

7. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

8. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

9. Solaris

compiled binary file gives "cannot execute binary file"

Hi, I have two Solaris machines. 1. SunOS X 5.8 Generic_108528-29 sun4u sparc SUNW,Sun-Blade-1500 2. SunOS Y 5.8 Generic_108528-13 sun4u sparc SUNW,Ultra-60 I am trying to buiild a project on both these machines. The Binary output file compiled on machine 2 runs on both the machines. Where... (0 Replies)
Discussion started by: scgupta
0 Replies

10. UNIX for Dummies Questions & Answers

binary file

please let me know how can i mail the binary files is it can be done thru pine? is there any other way to do it? wat are the changes in system i have to make and one more thing i am sending data to a message queue and then retriving the data from the queue but when i do the ipcs... (1 Reply)
Discussion started by: ramneek
1 Replies
Login or Register to Ask a Question