The command line is one of the most powerful tools in Linux. It allows you to execute commands, manage files, and automate tasks all from a single terminal window.
One common task you'll often need to do is run a file, whether it’s a script, a compiled program, or even a text file.
In this article, you'll learn how to run different types of files from the Linux command line.
Running Files in Linux
In Linux, you can run files using two methods. The first is through the file manager, where you can double-click on executable files to run them. The second is by using the terminal command line, where you execute files with commands like ./filename. Here are both the ways:
Method 1: By File Manager
Using a file manager, navigate to the folder containing the file. Right-click on the file, choose "Open With", and select the appropriate application to open it. Here is how you can do it -
1. Open the File manager:

2. Right click on the desired file and select "open with":

You may see your file running now.
Method 2: By Terminal Command Line
To run a file in Linux using the terminal, follow these steps:
1. Navigate to the File’s Directory: Use the cd command to change to the directory containing the file, e.g., cd /path/to/directory.

2. Check Permissions: Ensure the file has execute permissions by running ls -l filename. If not, add permissions with chmod +x filename.

3. Run the File: Use ./filename to execute the file.

Types of File you can Run on Linux
Running a file in Linux using the command line can involve executing scripts, compiled programs, or opening files with specific applications.
1. Running Shell Scripts
Shell scripts are text files containing a series of commands that the Bash shell (or other shells like Zsh) can execute. These scripts are typically used for automating tasks like system administration, file manipulation, or running commands in sequence. Shell scripts usually have the .sh file extension, but it’s not mandatory.
For complete tutorial, read - How to Run a Shell Script in Linux
Step 1: Make the Script Executable
Use the chmod command to give execution permission:
chmod +x filename.shStep 2: Run the Script
Execute the script using:
./filename.sh2. Running Python Files
Python files typically have a.pyextension and are used to execute Python code.
For complete, tutorial read - Open and Run Python Files in the Terminal
- Ensure Python is Installed
- Create a Python File
- Navigate to the Directory Containing the Python File
- And then, run the python file using:
python3 filename.pyExample:

3. Running Executable Files (.bin, .run)
Executable files like .bin and .run are often used for installing software or running standalone programs on Linux. These files are typically packaged to work on Linux systems without needing installation via a package manager.
Step 1: Download or Move the Executable to a Known Location
First, ensure the .bin or .run file is on your system. You can download or move it to a folder like ~/Downloads or any location you prefer.
Step 2: Navigate to the Directory Containing the Executable
Use the cd command to navigate to the directory where the .bin or .run file is saved. For example, if the file is in ~/Downloads:
cd ~/DownloadsStep 3: Make the File Executable
By default, .bin and .run files are not executable. You need to give them execute permissions first. Run the following command to make the file executable:
chmod +x filename.bin
After making the file executable, run it with:
./filename.bin4. Running Text Files or Other Non-Executable Files
To open text files or non-executable files in the terminal, Use a text editor (e.g., nano, vim, or cat):
vim filename.txtPress enter, and the file gets executed.
How to Check File Permissions in Linux
To ensure that a file is executable or accessible, it’s important to verify its permissions. Here's how you can check file permissions using the command line:
Using ls -l Command
The most common way to check file permissions is by using the ls -l command, which displays detailed information about files and directories:
ls -lWhen you run this command, you'll see something like this:
-rwxr-xr-x 1 user group 12345 Jan 1 12:34 filename.shYou can learn more on linux file permissions here.
Also Read:
- file command in Linux with examples
- How to Make Script Executable in Linux | chmod Command
- How to Fix - Reading A File: Permission Denied on Linux
Conclusion
Whether you’re dealing with scripts, executable files, or documents, knowing the right commands and steps ensures smooth execution in running files in the Linux command line. From making files executable with chmod to troubleshooting common errors, this guide has covered everything you need to get started. Always remember to be cautious with permissions and security to keep your system safe. With these tools, you can navigate your Linux system confidently and efficiently.