Running a file on Linux depends on whether it is a script, a binary, or an archive. If you are new to Linux, understanding how to run a file on Linux can feel confusing at first. But once you know the basic commands, it becomes second nature. This guide walks you through every common scenario step by step.
How To Run A File On Linux
Linux treats files differently than Windows. You don’t just double-click everything. Instead, you use the terminal or file manager with the right permissions. Let’s break down the main file types you will encounter.
Understanding File Types In Linux
First, know what kind of file you have. Linux files fall into three main categories:
- Binary executables – compiled programs like
firefoxorgcc - Scripts – text files with commands, like bash, Python, or Perl scripts
- Archives – compressed files like
.tar.gz,.zip, or.deb
Each type needs a different method to run. We’ll cover all of them.
Check File Permissions First
Before you run anything, check if the file has execute permission. Use the ls -l command. Look for the letter x in the file’s permission string. For example:
ls -l myfile
If you see -rwxr-xr-x, the file is executable. If you see -rw-r--r--, it is not. To add execute permission, use:
chmod +x myfile
This is a common step people forget. Always check permissions first.
Running Binary Executables
Binary files are already compiled. They are ready to run. To execute a binary in the current directory, type:
./filename
The ./ tells Linux to look in the current folder. If the binary is in a system path like /usr/bin, you can just type its name. For example:
ls
That runs the ls binary without any path prefix. But for your own files, always use ./.
What If The Binary Doesn’t Run?
If you get a “Permission denied” error, you need to set the execute bit. If you get “command not found”, the file might not be in your PATH. Use the full path or ./.
Running Shell Scripts
Shell scripts are text files with a .sh extension. They contain commands the shell understands. To run a shell script, you have two options:
- Make it executable and run it:
chmod +x script.shthen./script.sh - Run it with the shell interpreter:
bash script.shorsh script.sh
The second method does not require execute permission. This is handy for quick tests. But for regular use, setting the execute bit is cleaner.
Shebang Line Matters
Look at the first line of the script. It usually starts with #!/bin/bash or #!/usr/bin/python3. This tells the system which interpreter to use. If the shebang is missing, the script may not run correctly.
Running Python Scripts
Python scripts end in .py. You can run them directly if they have a shebang and execute permission:
./myscript.py
Or you can call Python explicitly:
python3 myscript.py
This works even without execute permission. Make sure you have Python installed. Check with python3 --version.
Running Perl, Ruby, And Other Scripts
The pattern is the same. For Perl:
perl script.pl
For Ruby:
ruby script.rb
Always use the correct interpreter. If the script has a shebang, you can make it executable and run it directly.
Running Compiled C Or C++ Programs
If you compile a C program with gcc, the output is a binary. Run it with ./a.out or whatever name you gave. For example:
gcc myprogram.c -o myprogram
./myprogram
The binary needs execute permission. The compiler usually sets this automatically.
Running Java Programs
Java is different. You compile to bytecode with javac, then run with java. For example:
javac MyClass.java
java MyClass
Do not add .class extension when running. Java looks for the class file automatically.
Running Archives Like Tar.Gz Or Zip
Archives are not directly executable. You must extract them first. For .tar.gz files:
tar -xzf archive.tar.gz
This extracts the contents. Then navigate into the folder and look for an executable or a script. For .zip files:
unzip archive.zip
After extraction, check the README file. It often tells you how to run the program.
Running .Deb Or .Rpm Packages
These are package files for Debian and Red Hat systems. You don’t run them directly. Instead, install them with the package manager. For .deb:
sudo dpkg -i package.deb
For .rpm:
sudo rpm -i package.rpm
After installation, the program is available system-wide. You can run it by typing its name.
Running AppImage Files
AppImage is a portable format. It bundles the application and its dependencies. To run an AppImage:
- Make it executable:
chmod +x app.AppImage - Run it:
./app.AppImage
No installation needed. This is great for testing software.
Running Flatpak And Snap Applications
Flatpak and Snap are modern package systems. They run in sandboxes. To run a Flatpak app:
flatpak run com.example.app
For Snap:
snap run appname
You usually install these from a store. After installation, you can also run them from the application menu.
Running Files With Wine (Windows Programs)
Wine lets you run Windows executables on Linux. Install Wine first. Then run:
wine program.exe
Not all Windows programs work. Check the Wine AppDB for compatibility.
Running Files From The File Manager
You don’t always need the terminal. Most file managers let you double-click executables. But you may need to set permissions first. Right-click the file, go to Properties, then Permissions, and check “Allow executing file as program”. Then double-click to run.
This works for scripts and binaries. For archives, the file manager may extract them automatically.
Common Errors And How To Fix Them
Here are frequent issues you might see:
- Permission denied – Use
chmod +x filename - Command not found – Use
./filenameor full path - No such file or directory – Check the file path and spelling
- Exec format error – The file is not a valid binary for your system
- Missing interpreter – Install the required language (Python, Perl, etc.)
Most errors are easy to fix. Read the error message carefully.
Using Sudo To Run Files
Some files need root privileges. Use sudo before the command:
sudo ./installer.sh
Be careful with sudo. Only use it when necessary. Running unknown files as root can damage your system.
Running Files In Background
If a program takes a long time, you can run it in the background. Add an ampersand at the end:
./longprocess &
This returns the terminal prompt immediately. The process runs in the background. Use jobs to see it.
Running Files With Arguments
Many programs accept arguments. For example:
./myprogram --help
Or:
python3 script.py input.txt
Arguments are separated by spaces. Check the program’s documentation for available options.
Running Files From Any Directory
If you want to run a file without typing the path, add its directory to your PATH. Edit your .bashrc file:
export PATH=$PATH:/path/to/directory
Then reload with source ~/.bashrc. Now you can run the file by name alone.
Running Scripts At Startup
You can configure scripts to run when the system boots. Add them to cron with @reboot or place them in /etc/init.d. For user-specific startup, use ~/.config/autostart.
Running Files With Different Shells
If you use a different shell like Zsh or Fish, the commands are the same. The ./ syntax works everywhere. Just make sure the shebang points to the correct interpreter.
Running Files On Remote Servers
If you are logged into a remote server via SSH, the same rules apply. Use ./filename after setting permissions. For scripts, you can run them with bash filename.
Running Files With Docker
Docker containers run applications in isolation. To run a file inside a container, you build an image first. But you can also run a command directly:
docker run ubuntu bash -c "echo Hello"
This is more advanced. For basic file execution, stick with the methods above.
Frequently Asked Questions
How Do I Run A .Sh File In Linux?
Make it executable with chmod +x file.sh, then run it with ./file.sh. Or use bash file.sh without changing permissions.
What Does ./ Mean In Linux?
The ./ means “current directory”. It tells the shell to look for the file in the folder you are currently in.
Can I Run A Windows .Exe File On Linux?
Yes, with Wine. Install Wine and run wine program.exe. Not all .exe files work perfectly.
Why Do I Get “Permission Denied” When Running A File?
The file does not have execute permission. Use chmod +x filename to add it.
How Do I Run A Python Script In Linux?
Use python3 script.py or make it executable with a shebang and run ./script.py.
Now you know how to run a file on Linux for almost every situation. Start with checking permissions, then use the right command for your file type. Practice in the terminal and it will become automatic. Linux gives you full control over your files, so use it wisely.