Method of starting program in Linux terminal using background running mode

Time:2022-6-16

This is a short but very useful tutorial that can help you launch a Linux Application on the terminal without losing focus on the terminal window.

There are many ways to open a terminal window in Linux, depending on your choice and your desktop environment.

If you are using Ubuntu, you can use ctrl+alt+t to open the terminal. Of course, you can also use the super key (Windows key) to open dash, search for “term”, and then click the “term” icon to open the terminal window.

For other desktop environments, such as xfce, KDE, lxde, cinnamon and mate, you can find the terminal in the menu. Some environments include terminal icons on docks or panels.

Usually, you can directly enter the application name in the terminal to start an application. For example, you can start Firefox by typing “Firefox”.

The advantage of launching the application at the terminal is that you can include some additional parameters.

For example, you can open a Firefox browsing window with the following command, and then use the default search engine to search for relevant information:

   

Copy code

The codes are as follows:

firefox -search “linux.cn”

You may notice that if you start Firefox, the program opens and returns to the terminal window control, which means that you can continue to work on the terminal.

Normally, if you start an application at the terminal, the control will switch to the newly started application. Only after the program is closed will it switch to the terminal control again. This is because you started the program at the front desk.

If you want to open an application on a Linux terminal and return to terminal control, you need to start the application as a background process.

Like the commands listed below, we can start the application in the background by adding a (&) symbol.

   

Copy code

The codes are as follows:

libreoffice &

Translator’s note: if you need to add parameters, remember to put the & symbol at the end.

Note: generally, when the terminal is closed, the background program started at the terminal will also be terminated. To keep the background program running after the terminal is closed, you can use the following commands

   

Copy code

The codes are as follows:

nohup command [arg…] &

If the application directory is not installed in the directory contained in the path variable, there is no way to start the program directly through the application name. You must enter the entire path of the application to start it.

   

Copy code

The codes are as follows:

/path/to/yourprogram &

If you are not sure which Linux directory structure the program enters, you can use the find or location command to locate it.

You can find a file by entering the following symbols:

   

Copy code

The codes are as follows:

find /path/to/start/from -name programname

For example, you can find Firefox by entering the following command:

   

Copy code

The codes are as follows:

find / -name firefox

The result of the command will be a lot of output. Don’t worry. You can also view it in pages through less or more.

   

Copy code

The codes are as follows:

find / -name firefox | more

find / -name firefox | less

When the find command finds a folder that does not have permission to access, an access denied error will be reported,

You can prompt permission through sudo command. Of course, if you do not install sudo, you can only switch to a user with permission.

   

Copy code

The codes are as follows:

sudo find / -name firefox | more

If you know that the file you are looking for is in your current directory structure, you can use a dot instead of a slash:

   

Copy code

The codes are as follows:

sudo find . -name firefox | more

You may need sudo to upgrade permissions, or you may not need it at all. If this file is in your home directory, you do not need to use sudo.

Some applications must be upgraded to run, otherwise you will get a lot of access denied errors, unless you use a user with permissions or use sudo to upgrade permissions.

Here’s a tip. If you run a program, but it needs to be operated with elevated permissions, enter the following command to try:

   

Copy code

The codes are as follows:

sudo !!