Configuring your Linux firewall to accept incoming connections on a specific port requires a single `iptables` or `firewalld` command. But before you tweak network settings, you first need to know **how to open a program in linux terminal**—and that is exactly what this guide covers. Whether you are a beginner or a seasoned user, launching applications from the command line is a fundamental skill that saves time and gives you more control over your system.
Opening a program in the Linux terminal is surprisingly simple. You just type the program’s name and press Enter. But there are many nuances—like running programs in the background, using full paths, or dealing with permission issues. This article will walk you through every method step by step.
How To Open A Program In Linux Terminal
The most direct way to open a program is by typing its executable name. For example, to launch the Firefox web browser, you would type:
firefox
Press Enter, and Firefox opens. That is the core of **how to open a program in linux terminal**. But what if the program is not in your PATH? Or what if you want to run it in the background so you can keep using the terminal? Let’s break down all the scenarios.
Using The Program Name Directly
Most common Linux programs are installed in directories like `/usr/bin` or `/usr/local/bin`. These directories are included in your system’s PATH variable. When you type a program name, the shell searches these directories automatically.
- Example: `gedit` opens the GNOME text editor.
- Example: `nautilus` opens the file manager.
- Example: `vlc` opens the VLC media player.
If you are unsure whether a program is installed, you can check with the `which` command:
which firefox
This returns the path to the executable if it exists. If nothing appears, the program is not installed or not in your PATH.
Using The Full Path To The Executable
Sometimes a program is located in a non-standard directory. In that case, you must provide the full path. For instance, if you downloaded a script to your Downloads folder, you would run:
/home/username/Downloads/myprogram.sh
Or use a relative path if you are already in the Downloads folder:
./myprogram.sh
The dot-slash (`./`) tells the shell to look in the current directory. This is essential for scripts or binaries that are not in your PATH.
Running Programs In The Background
When you launch a program from the terminal, it usually takes over the terminal window. You cannot type new commands until the program closes. To avoid this, append an ampersand (`&`) to the command:
firefox &
This starts Firefox in the background. The terminal returns control to you immediately. You can check background jobs with the `jobs` command:
jobs
To bring a background job to the foreground, use `fg` followed by the job number.
Using The Terminal To Open GUI Applications
Many Linux programs have both a command-line interface (CLI) and a graphical user interface (GUI). For GUI apps, typing the program name usually launches the window. But some programs require specific flags or arguments.
For example, to open a specific file with Gedit:
gedit /path/to/file.txt
To open a directory with Nautilus:
nautilus /home/username/Documents
You can also combine flags. For instance, to open Firefox in private mode:
firefox --private-window
Opening Programs That Require Root Privileges
Some programs need administrative access to run. In that case, prefix the command with `sudo`:
sudo gparted
You will be prompted for your password. Be careful—running programs as root can be dangerous if you do not trust the software.
For GUI applications that need root, it is often better to use `pkexec` or `gksudo` (if installed) for a graphical password prompt:
pkexec gedit
Using The Terminal To Open Terminal-Based Programs
Not all programs are graphical. Many are purely text-based and run inside the terminal itself. Examples include `nano` (text editor), `htop` (system monitor), and `mc` (file manager).
To open these, just type the command:
nano myfile.txt
This opens the file in the nano editor within the terminal. To exit, press Ctrl+X.
Opening Programs From A Different Directory
If you are in a different directory and want to run a program from another location, you can use the full path as mentioned earlier. Alternatively, you can change to that directory first:
cd /path/to/program
./programname
Or use a single command with the path:
/path/to/program/programname
Using The `Xdg-open` Command
Linux has a handy command called `xdg-open` that opens a file or URL with the default application. For example:
xdg-open https://example.com
This opens the URL in your default web browser. Similarly, to open a PDF:
xdg-open document.pdf
This is useful when you do not know or care which program handles the file type—the system decides.
Creating Aliases For Frequently Used Programs
If you find yourself typing long commands often, create an alias. For example, to make `ff` open Firefox:
alias ff='firefox'
Add this line to your `~/.bashrc` or `~/.bash_aliases` file to make it permanent. After reloading the file with `source ~/.bashrc`, you can just type `ff` to open Firefox.
Using The `&>` To Suppress Output
Sometimes a program prints messages to the terminal that clutter your screen. To suppress both standard output and error messages, use:
firefox &>/dev/null &
This sends all output to the null device (essentially discarding it) and runs the program in the background.
Opening Programs With Specific Environment Variables
Some programs require certain environment variables to run correctly. You can set them inline:
LANG=en_US.UTF-8 firefox
Or export them first:
export LANG=en_US.UTF-8
firefox
Troubleshooting Common Issues
Sometimes a program does not open as expected. Here are common problems and solutions:
- Command not found: The program is not installed or not in your PATH. Install it with your package manager (e.g., `sudo apt install firefox`).
- Permission denied: The file is not executable. Use `chmod +x filename` to make it executable.
- Segmentation fault: The program crashed. Check for updates or reinstall.
- Library errors: Missing dependencies. Install them via your package manager.
Using The Terminal To Open Programs In A New Terminal Window
If you want to open a program in a new terminal window (so you can keep the original terminal free), use the terminal emulator’s own command. For example, with GNOME Terminal:
gnome-terminal -- firefox
This opens a new terminal window and runs Firefox inside it. The original terminal remains usable.
Opening Programs With Arguments And Options
Most programs accept command-line arguments. For example, to open a specific website in Firefox:
firefox https://www.google.com
To open a file in VLC:
vlc /path/to/video.mp4
Check the program’s help with `–help` or `-h` to see all available options.
Using The `Nohup` Command To Keep Programs Running
If you close the terminal, background programs usually terminate. To prevent this, use `nohup`:
nohup firefox &
This makes the program immune to hangup signals. The output is saved to `nohup.out` by default.
Opening Programs With `Flatpak` Or `Snap`
Many modern Linux distributions use Flatpak or Snap for package management. To open a Flatpak program:
flatpak run org.mozilla.firefox
For Snap:
snap run firefox
You can also find the exact application ID with `flatpak list` or `snap list`.
Using The `Type` Command To Locate Programs
The `type` command tells you how a command would be interpreted:
type firefox
It might return something like `firefox is /usr/bin/firefox` or `firefox is aliased to ‘firefox –private-window’`. This helps you understand what actually runs when you type a name.
Opening Programs From The Run Dialog (Alt+F2)
While not strictly terminal, many Linux desktops have a Run dialog (Alt+F2) that accepts terminal commands. You can type the program name there to launch it without opening a terminal first.
Using Scripts To Open Multiple Programs
You can create a shell script to open several programs at once. For example, create a file called `startwork.sh`:
#!/bin/bash
firefox &
thunderbird &
gedit &
Make it executable with `chmod +x startwork.sh` and run it with `./startwork.sh`. This opens all three programs simultaneously.
Opening Programs With `Systemd-run`
For advanced users, `systemd-run` can start programs as transient systemd services:
systemd-run --user firefox
This gives you more control over the process, including logging and resource limits.
Common Mistakes When Opening Programs
Even experienced users make errors. Here are the most frequent ones:
- Typing the wrong name: Double-check the program’s exact name.
- Forgetting the ampersand: Without `&`, the terminal is blocked.
- Using `sudo` unnecessarily: Only use root privileges when required.
- Not using quotes for paths with spaces: Use `”path with spaces”` or escape spaces with `\`.
Advanced Techniques
Opening Programs With `Setsid`
To run a program in a new session (detached from the terminal), use:
setsid firefox
This ensures the program continues even if the terminal crashes.
Using `Disown` After Starting A Program
If you forgot to use `&` and the program is running in the foreground, press Ctrl+Z to suspend it, then type:
bg
disown
This moves it to the background and removes it from the job table, so it survives terminal closure.
Opening Programs With Custom Working Directories
Some programs expect to be run from a specific directory. Use `cd` first or combine commands:
(cd /path/to/dir && ./program)
The parentheses create a subshell, so your current directory does not change.
Frequently Asked Questions
How Do I Open A Program In Linux Terminal If It Says “Command Not Found”?
First, check if the program is installed with `which programname` or `dpkg -l | grep programname`. If not, install it using your package manager (e.g., `sudo apt install programname` for Debian/Ubuntu). If it is installed but still not found, the directory might not be in your PATH—use the full path instead.
Can I Open A GUI Program From The Terminal Without It Blocking The Terminal?
Yes, append an ampersand (`&`) to the command. For example, `firefox &` launches Firefox in the background and returns control to you immediately. You can also use `nohup` to prevent termination when closing the terminal.
What Is The Difference Between Opening A Program With `./` And Without?
Using `./` tells the shell to look in the current directory for the executable. Without it, the shell searches the directories listed in your PATH variable. Most installed programs are in PATH, so you can just type their names. For scripts or binaries in your current directory, you must use `./`.
How Do I Open A Program In Linux Terminal As A Different User?
Use the `su` or `sudo` command. For example, `sudo -u username programname` runs the program as the specified user. You can also switch users with `su username` and then run the program normally.
Why Does My Program Open But Immediately Close?
This often happens with GUI programs launched from the terminal without `&`. The program may print error messages and exit. Run it with `&` and check the terminal output for clues. Alternatively, run it with `strace` to see system calls, or check log files in `/var/log`.
Final Tips For Mastering Terminal Program Launching
Practice makes perfect. Start by opening your most-used programs from the terminal. Soon you will find it faster than clicking icons. Remember these key points:
- Use `&` for background execution.
- Use `./` for local scripts.
- Use `sudo` only when necessary.
- Create aliases for long commands.
- Use `xdg-open` for files and URLs.
With these skills, you can efficiently open any program from the Linux terminal. Whether you are a system administrator managing servers or a casual user exploring Linux, the command line gives you power and flexibilty. Start practicing today and you will wonder why you ever used the mouse.