How to Run Binary Files in Linux [2 Best Ways]

TL; DR

To run binary files in Linux, you can try any of the two methods below:

  1. 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.
  2. 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.

When dealing with binary files, you may need to troubleshoot some common issues, such as checking permissions, file location, and dependencies. To avoid such issues, keep your system up to date, use a package manager, and consider third-party tools for more efficient binary file management. Also, follow the best security practices. This includes only running the binary files from trusted sources, using antivirus software, and regularly backing up important data to keep your system safe and secure.

Check out my detailed and step-by-step guide below to easily run binary files on your Linux-based systems.

Binary files use a compact, machine-readable format that makes data transfer and processing efficient for computers and microcontrollers. However, running them in Linux can be challenging for beginners, particularly without familiarity with the command-line interface.

To help you out, I’ve written this comprehensive guide to explain everything you need to know for optimal binary file execution on your Linux. You’ll also learn how to troubleshoot some common issues and run binary files efficiently with my expert tips and apply best security practices.

How to Run Binary Files in Linux

To run binary files in Linux, you have two options, the Terminal app or the GUI. 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.

  1. Open the nano text editor in the Terminal app using the command below.
nano
  1. 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
  1. 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.
create binary files using the terminal
  1. Make the file executable by running the command:
chmod +x binary_script.sh
  1. Run the script in the terminal and press Enter.
./binary_script.sh
  1. The script will create a binary file called binary_file in the same directory.
create binary file in same directory
  1. 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.
pause 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:

  1. Head to the directory where the executable binary file is located using the file manager.
head to executable binary file location
  1. Right-click on the binary file and select Properties.
select properties by right clicking binary file run binary files
  1. In the Permissions tab, check the box that says Allow executing file as program.
allow executing file as program in permission tab
  1. Now, close the properties window and double-click on the binary file to run it in a new window.

8 Troubleshooting Issues of Binary Files in Linux

Sometimes, binary files may not run as expected due to a variety of issues. Here are some common issues and how to troubleshoot them:

  • 🔴 Incompatibility issues: In some cases, binary files may not run due to compatibility issues with the operating system or hardware. Ensure that the binary file is compatible with your system’s architecture and operating system version.
  • 💽 Corrupted file: If the binary file is corrupted, it may not run or may produce unexpected errors. Check the file’s integrity by comparing its hash with the original or downloading a new copy of the file.
  • 💻 Insufficient permissions: Binary files may require elevated permissions to run correctly. Ensure that you have the appropriate permissions, or try running the binary file with elevated privileges using the sudo command.
  • 🚪 Firewall restrictions: If your system’s firewall is blocking incoming or outgoing connections, it may prevent binary files from running correctly. Check your firewall settings to ensure that the necessary ports and protocols are open.
  • 📈 Performance issues: Some binary files may consume excessive system resources, leading to performance issues or crashes. Monitor system resource usage using tools like top or htop and adjust resource allocation as necessary.
  • 🔒 Permission denied: If you receive a “permission denied” error when trying to run a binary file, it means that the file is not executable. Use the chmod command to make the file executable.
  • 🔍 Missing dependencies: Some binary files require additional libraries or dependencies to run correctly. Check the documentation for the binary file to see if any dependencies are required and install them if necessary.
  • 📂 File not found: If you get a “file not found” error when trying to run a binary file, check that you are in the correct directory and that you have spelled the file name correctly. Use the ls command to see the list of files in the current directory. Then, note the name of the files that you wish to run on your Linux machine and try to execute the desired binary file again.

6 Best Security Practices to Run Binary Files in Linux

Running binary files in Linux can introduce security risks, especially if the files come from untrusted or unknown sources. Here are 6 security best practices to safely run binary files in Linux:

  • 🔄 Keep your system up to date: Make sure that your Linux system is up to date with the latest software updates and security patches. Use the command sudo apt update && sudo apt upgrade to update and upgrade your system. This will protect your system if you experience any security issues when running binary files on your Linux system
  • 🔒 Only run binary files from trusted sources: Before running a binary file, make sure that it comes from a trusted source and has not been tampered with. Use the sha256sum command to verify the checksum of the binary file.
  • 🛡️ Use antivirus software: If you want to run binary files, install and regularly update antivirus software to help detect and remove malware from your system. Use a trusted antivirus software such as ClamAV, and update it regularly using the command sudo apt update && sudo apt install clamav && sudo freshclam.
  • 💾 Keep backups: Regularly back up your important data to ensure that you can recover it in case of a security breach or data loss. Use the rsync command to synchronize your data with an external hard drive or cloud storage.
  • 📦 Use a package manager: Whenever possible, use a package manager to install software and dependencies. This can help ensure that all dependencies are installed correctly and that you are running the latest version of the software from its official sources. Use the sudo apt install <package-name> command to install a package.
  • 🔧 Consider trusted third-party tools: There are several third-party tools available that can help you run binary files more efficiently in Linux. Some popular and trusted tools include Wine, which allows you to run Windows programs on Linux, and PlayOnLinux, which makes it easy to install and run Windows games on Linux. Install Wine using the command sudo apt install wine and PlayOnLinux using the command sudo apt install playonlinux.

In Conclusion

Having a good grasp of how to run binary files is an essential skill for you as a Linux user. It will help you install and use apps that may not be available through the standard package manager. Furthermore, with my expert tips and best practices discussed in this guide, you can easily run binary files. In fact, it will also help you become a more knowledgeable and competent Linux user.

If you’re interested in expanding your knowledge of the Linux file system, check out my articles on how to view file content, count files in a directory, and explore efficient ways of renaming directories in Linux. My practical tips and tricks will help take your Linux expertise to the next level. Read them now!

Frequently Asked Questions

What are Binary files?

Binary files store data in a format that is machine-readable, such as computers or microcontrollers. They are typically used to store executable code, images, audio, video, and other types of data in zeros and ones. This format allows binary files to be much smaller than text files and allows them to be accessed much more quickly.

How do I know if a binary file is malicious?

Unfortunately, it can be difficult to determine if a binary file is malicious or not, especially if the file comes from an unknown or untrusted source. However, there are some steps you can take to minimize the risk of running a malicious binary file. Always run binary files from trusted sources, use antivirus software to scan your system for malware, and keep your system and software up to date with the latest security patches.

What are the types of Binary files?

There are several types of binary files, including:
– 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?

Optimizing a binary file for your Linux system can help it run more efficiently and effectively. Some tips for optimization include using a package manager to install dependencies, compiling the binary file specifically for your Linux distribution, and removing any unnecessary code or features from the binary file.

Can I run 32-bit binary files on a 64-bit Linux system?

Yes, you can run 32-bit binary files on a 64-bit Linux system using the ia32-libs package or a similar tool. However, keep in mind that running 32-bit binary files on a 64-bit system can introduce compatibility issues and may require additional configuration.

What are the ways to create and run binary files?

There are several ways to create binary files. However, some popular ways to create them are:
– 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.

If a binary file fails to run in Linux, what are the possible actions to take?

If a binary file does not run in Linux, there are several things you can try. First, make sure that the file is executable and that you are running it correctly. If the file still does not run, check the documentation for the binary file to see if any additional dependencies or libraries are required. If all else fails, you may need to seek assistance from the software developer or a Linux support forum.

Total
0
Shares