TL; DR
To run binary files in Linux, you can try any of the two methods below:
- Terminal app: Execute the
chmod + x filename.extension
command to make the file executable and then enter./filename
to run the script in the Terminal. - GUI: Right-click on the binary file, select Properties, and check the box that says Allow executing file as program. Then, double-click the executable file to run it in a new window.
Check out my detailed and step-by-step guide below to easily run binary files on your Linux-based systems.
Running binary files in Linux can seem confusing if you’re new to it. Many users struggle with getting these files to work correctly. In this post, I’ll show you how to run binary files using both the terminal and GUI. You’ll also learn key security practices to keep your system safe from potential threats. By following these steps, you’ll gain confidence in handling binary files and ensure your Linux system runs smoothly.
What are Binary Files?
A binary file is a type of file that contains data in a format that a computer can read but humans usually cannot. Unlike text files, which store data as plain text that you can read, binary files store data as a series of ones and zeros.
This data can represent anything from an image to an executable program. Binary files are efficient for computers to process because they are in a format that the computer’s hardware understands directly.
Differences Between Binary and Text Files
Aspect | Text Files | Binary Files |
---|---|---|
Format | Plain text using characters like letters, numbers, and symbols. Each character is represented by a specific code (e.g., ASCII). | Binary format, which is a series of ones and zeros. Not meant to be read by humans directly. |
Readability | Human-readable; can be opened and read using simple text editors like Notepad or Vim. | Not human-readable; opening in a text editor shows random characters and symbols. |
Use Cases | Used for documents, source code, and configuration files (e.g., .txt, .csv, .html). | Used for executable programs, compiled code, and complex data storage (e.g., .exe, .bin, .png). |
Size and Efficiency | Usually larger due to more space needed for characters; easy to edit but less efficient for complex data. | More compact and efficient; stores data in the format the computer uses directly, making them faster to read and write. |
How to Run Binary Files in Linux
To run binary files in Linux, you can use either the terminal or the GUI. In the terminal, navigate to the file’s directory, make it executable with chmod +x filename
, and run it with ./filename
. Alternatively, in the GUI, locate the file in the file manager, right-click, select Properties, check Allow executing file as program, and double-click the file to run it.
Here, I am going to explore both of these ways to run binary files on your Linux system.
1. Run Binary Files Using the Terminal
The most common way to run a binary file in Linux is through the Terminal app. Here are the step-by-step instructions to create and run the binary file in Linux. However, you can skip the creation process if you already have a binary file and directly jump to step 4.
- Open the nano text editor in the Terminal app using the command below.
nano
- Copy and paste the following code into the text editor:
#!/bin/bash
# Create a binary file
echo -ne "\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20\x62\x69\x6e\x61\x72\x79\x20\x66\x69\x6c\x65" > binary_file
# Read the binary file and display the output
cat binary_file
- Press Ctrl + O to save the file with a .sh extension and press Enter. After saving the file, press Ctrl + X to exit the nano editor.

- Make the file executable by running the command:
chmod +x binary_script.sh
- Run the script in the terminal and press Enter.
./binary_script.sh
- The script will create a binary file called binary_file in the same directory.

- If the output disappears from your Terminal interface, add a sleep command after the cat command to pause the script for a few seconds before exiting. For example, you can add the line sleep 10 after cat binary_file to pause the script for 10 seconds before exiting.

2. Run Binary Files Using the GUI
If you prefer not to use the terminal, you can also run binary files using the GUI. To do this, follow these steps:
- Head to the directory where the executable binary file is located using the file manager.

- Right-click on the binary file and select Properties.

- In the Permissions tab, check the box that says Allow executing file as program.

- Now, close the properties window and double-click on the binary file to run it in a new window.
Essential Security Practices for Running Binary Files in Linux
Running binary files on Linux can be risky if you don’t take the right steps. By following some key practices, you can protect your system from potential threats. Here are five important security measures to follow:
- 🔒 Use Security Tools: Employ tools like AppArmor or SELinux to enforce strict security policies. These tools help restrict what a binary file can do, adding an extra layer of protection to your system.
- 🔒 Download from Trusted Sources: Always download binary files from official websites or trusted sources. Avoid unknown or suspicious sites to reduce the risk of malware.
- 🔍 Verify File Integrity: Check the file’s integrity using checksums like
md5sum
orsha256sum
. Comparing the checksum with the one provided by the source ensures the file hasn’t been tampered with. - ⚙️ Check File Permissions: Ensure the binary file has the correct permissions. Use
chmod +x filename
to make it executable, and avoid giving unnecessary permissions that could lead to security risks. - 🛡️ Scan for Malware: Use antivirus tools like ClamAV to scan binary files for malware. Regularly scanning files helps detect and remove malicious code before it can harm your system.
Summing Up
In this article, I’ve covered the methods to run binary files in Linux using both the terminal and the GUI, providing step-by-step instructions for each approach. I also highlighted essential security practices to follow, such as using trusted sources, verifying file integrity, and employing security tools like AppArmor or SELinux to protect your system.
If you found this guide helpful, you might want to explore other relevant topics to deepen your Linux knowledge:
- Explore various commands and tools to view the contents of files, which can improve your efficiency in managing and editing files within the Linux environment.
- Learn how to display file sizes in a human-readable format to better manage your disk usage and understand storage consumption.
- Discover methods to set special permissions on files and directories, allowing you to enhance security and control access more precisely.
Frequently Asked Questions
What are Binary files?
How do I know if a binary file is malicious?
What are the types of Binary files?
– Executable files: These are files that contain machine code that can be executed by the operating system. Examples include programs, scripts, and compiled code.
– Libraries: These are collections of precompiled functions and subroutines that can be used by other programs.
– Object files: These are intermediate files that are generated during the compilation process and contain machine code that has not yet been linked to other files.
How can I optimize a binary file for my Linux system?
Can I run 32-bit binary files on a 64-bit Linux system?
What are the ways to create and run binary files?
– Compiling source code: Converting human-readable code into machine code that can be run directly on the operating system.
– Assembly: A low-level programming language that is used to write programs directly in machine code. Assembly language programs are usually stored in binary files.
– Image, audio, and video encoding: These files are stored in binary format to reduce their size and allow for faster access.