The Linux terminal is your direct line to running programs without a graphical interface. If you’re new to Linux, learning how to run a program in linux terminal might feel intimidating at first, but it’s actually quite straightforward once you understand the basics.
Think of the terminal as a powerful command center. You type a command, press Enter, and the program launches. No clicking, no menus—just pure efficiency. This guide will walk you through everything you need to know, from simple commands to advanced techniques.
Understanding The Linux Terminal
The terminal, also called the command line or shell, is a text-based interface. It lets you interact with your operating system directly. When you run a program, you’re telling the system to execute a file containing instructions.
Most Linux distributions come with a default terminal emulator. You can open it from your applications menu or by pressing Ctrl+Alt+T. Once open, you’ll see a prompt where you type commands.
Basic Terminal Commands You Should Know
Before running programs, get comfortable with a few essential commands:
pwd– Shows your current directory (where you are in the file system)ls– Lists files and folders in the current directorycd– Changes directory (e.g.,cd Documents)man– Displays the manual for a command (e.g.,man ls)clear– Clears the terminal screen
These commands help you navigate and find the program you want to run. Practice them until they feel natural.
How To Run A Program In Linux Terminal
Now let’s get to the core topic. There are several ways to run a program, depending on its type and location. Below are the most common methods.
Method 1: Running System Programs
System programs are installed in standard directories like /usr/bin or /bin. You can run them by typing their name directly.
- Open your terminal.
- Type the program name (e.g.,
firefoxfor the Firefox browser). - Press Enter.
Examples of common system programs:
gedit– Opens the text editornautilus– Opens the file managertop– Shows running processesping– Tests network connectivity
If the program is in your system’s PATH, it will run immediately. You can check if a program is in your PATH with which programname.
Method 2: Running Programs From A Specific Directory
Sometimes you need to run a program that isn’t in your PATH. For example, a downloaded script or a compiled program in your home folder.
- Navigate to the program’s directory using
cd. - Type
./followed by the program name (e.g.,./myprogram). - Press Enter.
The ./ tells the terminal to look in the current directory. Without it, the system searches only the PATH directories.
Note: You might need to make the file executable first. Use chmod +x filename to add execute permissions.
Method 3: Running Scripts (Bash, Python, Etc.)
Scripts are text files containing commands. To run them, you need an interpreter.
For a Bash script:
- Ensure the script has a shebang line (
#!/bin/bash) at the top. - Make it executable:
chmod +x script.sh. - Run it:
./script.sh.
For a Python script:
- Make sure Python is installed.
- Run it with:
python3 script.py.
You can also run scripts by calling the interpreter directly, even without execute permissions.
Method 4: Running Programs In The Background
Some programs take a long time or run continuously. You can run them in the background to free up your terminal.
Add an ampersand (&) at the end of the command:
firefox &
This launches Firefox and returns control to you. The program continues running in the background.
To bring a background job to the foreground, use fg. To list background jobs, use jobs.
Method 5: Running Programs With Arguments
Many programs accept arguments to modify their behavior. For example, you can open a specific file with a text editor.
gedit /home/user/documents/notes.txt
This opens the file directly in gedit. Arguments can be file paths, options (like --help), or flags (like -v for verbose mode).
Check a program’s documentation with man programname to see available arguments.
Common Issues And Solutions
Even experienced users run into problems. Here are frequent issues and how to fix them.
Command Not Found Error
If you see “command not found,” the program isn’t installed or isn’t in your PATH. Install it with your package manager (e.g., sudo apt install firefox on Debian/Ubuntu).
Permission Denied
This usually means the file isn’t executable. Run chmod +x filename to add execute permissions. If you’re trying to run a system command, you might need sudo.
Program Runs But Nothing Happens
Some programs run in the background or open a window. Check if the program is running with ps aux | grep programname. If it’s a GUI app, it might need a display server.
Program Freezes The Terminal
If a program hangs, press Ctrl+C to terminate it. For stubborn programs, use Ctrl+Z to suspend it, then kill %1 to end it.
Advanced Techniques
Once you’re comfortable with the basics, try these advanced methods.
Using Aliases For Frequently Run Programs
Aliases let you create shortcuts for long commands. Add them to your .bashrc file.
alias myeditor='gedit ~/notes.txt'
Now typing myeditor runs the full command. This saves time and reduces typos.
Running Programs With Sudo
Some programs require root privileges. Use sudo before the command.
sudo apt update
You’ll be prompted for your password. Be careful with sudo—it gives full system access.
Using Pipes And Redirection
Pipes (|) let you send output from one program to another. Redirection (> or <) sends output to a file or reads input from a file.
ls | grep .txt lists only text files.
echo "Hello" > file.txt writes "Hello" to a file.
These techniques are powerfull for combining programs.
Running Programs From A Different User
Use su to switch users, or sudo -u username command to run a command as another user.
sudo -u john ./script.sh
This runs the script as user "john." Useful for testing permissions.
Practical Examples
Let's put it all together with real-world scenarios.
Example 1: Running A Python Web Server
- Create a simple Python script named
server.py. - Make it executable:
chmod +x server.py. - Run it:
./server.py.
If you want it in the background: ./server.py &
Example 2: Opening A File With A Specific Program
Suppose you want to open a CSV file with LibreOffice Calc.
libreoffice --calc data.csv
This launches Calc and loads the file directly.
Example 3: Running A Compiled C Program
- Compile the program:
gcc -o myprogram myprogram.c - Run it:
./myprogram
You can pass arguments: ./myprogram --verbose
Tips For Efficient Terminal Use
- Use tab completion: Type the first few letters of a command or file name, then press Tab to auto-complete.
- Use the up arrow to recall previous commands.
- Use
historyto see all past commands. - Use
Ctrl+Rto search through command history. - Use
!!to repeat the last command.
These shortcuts will speed up your workflow significantly.
Frequently Asked Questions
How Do I Run A Program In Linux Terminal If It's Not In PATH?
Navigate to the program's directory using cd, then run it with ./programname. Make sure it's executable.
Can I Run A GUI Program From The Terminal?
Yes, most GUI programs can be launched from the terminal. Just type the program name. The terminal will stay open until the program closes, unless you use & to run it in the background.
What Does The Error "Bash: ./Program: Permission Denied" Mean?
It means the file isn't executable. Use chmod +x program to add execute permissions, then try again.
How Do I Stop A Program Running In The Terminal?
Press Ctrl+C to terminate it. If that doesn't work, try Ctrl+Z to suspend it, then kill %1 to end it.
Is There A Way To Run A Program Automatically At Startup?
Yes, you can add the command to your .bashrc or .profile file, or use systemd services for system-wide startup.
Conclusion
Running programs in the Linux terminal is a skill that grows with practice. Start with simple system commands, then move to scripts and background processes. The terminal gives you control and efficiency that graphical interfaces can't match.
Remember to check permissions, use the correct path, and leverage the man pages for help. With time, you'll find the terminal becomes your preferred way to interact with Linux.
Experiment with the examples in this guide. Try running different programs, passing arguments, and using background processes. Each mistake is a learning opportunity. Soon, you'll be running programs with confidence and speed.