How to Open an Application using the Terminal on Linux Mint

Share
In this tutorial, we'll learn how to execute an arbitrary program or open an application using the terminal on Linux Mint, including both installed applications and shell script files.

Executing Shell Script Files

Let's start with the process for shell script files, which is simpler.

Let's say you have a file called script.sh in a given folder (directory). In order to execute it, first we must make the file itself executable by changing its file permissions.

Execute the following command on the terminal [how?]:

chmod +x script.sh

The command above will give script.sh the executable permission if it exists in the current working directory.

After doing this, we can execute the script file with this command:

./script.sh

See [How to Refer to Files and Folders using the Terminal on Linux Mint] for details.

The same method works for .appimage files.

Other Interpreters

If the script file requires an interpreter other than the shell, e.g. it's a Python script, you'll need to write the appropriate shebang in the script file so the shell can figure out what interpreter to execute. For example, if you have a Python script file called script.py containing the following code:

#!/usr/bin/env python3
print("Hello world!")

You can execute it in 3 ways:

  1. By calling python3 script.py.
  2. By calling /usr/bin/env python3 script.py.
  3. By making it executable, and then simply calling ./script.py.

Executing Installed Applications

If an application is installed in the system, we can run it by providing its filepath as the zeroth argument in the command-line. For example:

/usr/bin/krita

The command above will open Krita if it's installed, because if it's installed an executable file will be created in the /usr/bin directory. That's what we're executing here.

Note: on Linux, filepaths are case-sensitive, which means /Usr/Bin/Krita or /USR/BIN/KRITA won't work as that's considered to be a different filepath.

Executing Applications by Name

Bash can execute a program by name if it's inside one of the directories listed in the $PATH environment variable, which includes /usr/bin by default. This means we can also run Krita through the command:

krita

Once again, keep in mind that this is case-sensitive and it only works because a file called krita exists in the /usr/bin directory.

Opening Files in Applications from The Command-Line

By convention, an application that opens files takes the filepath of a file to open as its first argument in the command-line. For example:

krita ~/my-file.kra

The command above will pass the filepath of a file called my-file.kra that exists in your home directory, represented in Bash by the tilde (~), to krita. Krita will then automatically open that file when it starts up. This is the same process that occurs whenever you double click on a file in a file manager to open it.

If an application can open files in multiple ways, there may be an option or flag you can use to modify how it opens a file. This depends on the application, though.

Written by Noel Santos.

About the Author

I'm a self-taught Brazilian programmer graduated in IT from a FATEC. In a world of increasingly complex and essential computers, I decided to use my technical expertise in hardware, desktop applications, and web technologies to create an informative resource to make PC's easier to understand.

View Comments