Open In App

Difference Between a Script file and a Binary file

Improve
Improve
Like Article
Like
Save
Share
Report

In this tutorial, we will learn what a script file and a binary file are and what’s the difference between a Script file and a Binary file.

Binary File

A binary file is a file in which the content of the file is in binary format, the file data is not human-readable. Binary files contain formatted information that only certain applications or processors can understand. All executable programs are stored in binary files. For example, a jpeg image is a binary file designed to be read by a computer program only.

Script File

A script file is a file containing the sequence of instructions written in any scripting language that needs to be executed in order. In Linux or Unix systems a script file contains a sequence of Linux commands that need to be executed and if one of the commands in the sequence is not executed others will also not execute, the extension of a script file is generally .sh  in Linux. Below is an example of a script file in Linux that prints “Hello World”:

Script File in Linux

Difference between a Binary File and a Script File

S. No. Script File Binary File
1. A script file is a file containing a sequence of instructions written in any scripting language that needs to be executed in order. The binary file contains formatted information in a binary format that can only be understood by certain applications or processors.
2. It stores data using ASCII characters format. It stores data in binary format i.e. with the help of 0 and 1.
3. Error in a script file can be easily recognized and eliminated. Error in a binary file corrupts the file and is not easily detected.
4. It is human readable It is not human readable
5. It can be modified easily It cannot be modified by humans directly, it needs special software to modify them
6. It can be viewed using a text editor or any text viewer It needs specified software to view the binary file, for example, you need an image viewer to view the binary file of the image
7. It is written in High-Level Language It is written in Low-Level Language
8. Extension of shell script file generally: .sh, .csh, etc Extensions are generally: .bin, .dat

How to check whether a  file is a binary file or a script file?

  • Checking extension 
  • Using the file command

1. Checking extension

A shell script usually has the file extension .sh (Bourne or Korn shell) or .csh (C shell) whereas extensions of binary files are .bin, .dat. You can verify any file by just looking at the file extension, in the below image you can clearly see that dmyscipt.sh file has extension .sh hence it’s a shell script file and dlibex.dat has a .dat extension which is of the binary file hence it is a binary file, we will verify it by file command also in the below section.

 

2. Using the file command

file command helps in determining the type of the file and its data. The command doesn’t take the file extension into account instead, it runs a series of tests to discover the type of file data. 

file [option] [file name]

To find out whether the file is a script file or binary we used the file command on two different files to find out that, one file is a script file dmyscript.sh which is a Bourne-Again shell script file and another is a binary file which is present in /bin directory and the file command shows that it is a binary file, see the difference in the below output image:-

 

In this article, we hope you understand what is a binary file and a script file, what is the difference between them, and how to check whether it’s a binary file or a script file.


Last Updated : 09 Dec, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads