Starting apps in linux

Start and stop application from terminal in Linux Mint 19 / Ubuntu 18.04

In this article we will review several scenarios how to :

  • Start application from terminal — Ubuntu / Linux Mint
  • Schedule application start
  • Build script starting application
  • Stop application by id/name in Linux Mint / Ubuntu
  • Application stop with delay
  • Auto logout from Ubuntu / Linux Mint
  • Bonus tip: schedule application stop

Start application from terminal — Ubuntu / Linux Mint

In order to start application from terminal you need to know the name of the application which is used in the system. Sometimes the system name can differ from the application name. For example:

  • Chrome — google-chrome
  • Chromium — chromium-browser
  • Sublime — subl

You can find where a given application is installed by:

Also there you can search for applications.

In order to start give application you need to write it’s name in the terminal:

You can pass different parameters to the application which will be opened. For example which file to be opened for Libre office:

or what web sites to be opened with chrome:

Schedule application start

Sometimes you may want to schedule a script for opening a given application. In order to improve my performance and decrease the distractions I’m scheduling my mail to be opened two times per day: 10:00 and 16:00.

The scheduling in Linux usually is done with cron jobs:

  • Open terminal
  • Type: crontab -e — for current user only or sudo crontab -e
  • finally add your job:

Some application can be started by their name but others will need some settings. For example in order to start thunderbird and display it you need to add this line in your crontab file:

the same way if you are using bash script to start another application. For example starting LibreOffice calc:

where libre office will be started after a csv file with data is downloaded from a website.(I’ll add new article on this topic).

Build script starting application

Building special scripts to start application can be helpful in order to automate boring stuff. I have 10 scripts which are helping me to do boring stuff like:

  • reporting
  • getting information from the web
  • sending mails
  • analysing data
  • starting and stoping application — obviously from the article 🙂

Below you can find several examples below:

  • the first row is going to «log» each time this scripted is executed
  • the second one is opening thunderbird

A more complex example where:

this example is more complex. Here is what is done:

  • activate special python virtual environment
  • change to a special folder
  • run a web spider in order to get information from Google
  • analyze and change the data
  • load the download data in calc

this script is run with a cron job every day and retrieves important information for me. If I need to do the same thing I’ll need to spend 10 to 30 minutes per day.

Читайте также:  Как создать папку через терминал windows

Stop application by id/name

To stop application from the terminal by id you will need to find the id first. This can be done by this command:

10882 10869 10831 10784 10781

Another alternative is:

10882 10869 10831 10784 10781

or the more verbose one:

user 2315 0.0 0.0 15648 1152 pts/1 S+ 18:38 0:00 grep —color=auto google-chrome
user 10781 0.3 0.4 1379564 151624 ? SLl 14:57 0:47 /usr/lib/..

and then you can extract the pid-s.

After that in order to stop the application you can use:

both do similar things but the one with -9 is more «aggressive» and forcing.

In order to stop/kill application by name you can use:

this is going to kill multiple processes by name.

Application stop with delay

Now let say that you want to stop a given application with some delay: 10 minutes, 1 hour or something else. You can do with by several different ways: cron job, script, third party software. In this case we will use simple script:

this script will wait for 1 hour and then will stop the application. So you can use a script to start a given application. This application to be executed for 1 hour and finally to be stopped.

Other times examples:

Note: You can’t use:

Auto logout from Ubuntu / Linux Mint

The final problem which we are going to cover in the article is about log out of inactive users. There is application for Ubuntu / Linux Mint which can be used — autolog. You can search in the software center and install it. Or you can install it by:

Bonus tip: schedule application stop

Let say that you work a lot google chrome, slack, zoom, pycharm or any other application in Linux Mint, Ubuntu. Most of the time is really difficult to end up your working day and leave your workplace. Automation to the rescue! Below you can find a simple script and how to use in order to schedule stop for your applications in Linux:

The script will show the current date and time. Then will wait for a given period of time ( in this case 30 minutes ) and finally will kill the application.

now you can schedule this script as a cronjob by:

Источник

How to automatically run program on Linux startup

There are a few stages of Linux startup, and you can set your own autostart script or program at any of the stages where it could be a single command, a chain of commands, or an executable shell script. There could be, however, some differences in startup procedure between different Linux distributions and versions.

Modern Linux will first boot into systemd while older versions of Linux uses System V init. Both methods will run cron and rc.local before the desktop environment such as GNOME or KDE is loaded. On the other hand, server-based Linux distributions will run the default shell such as Bash after the user logged in at the console instead of loading the desktop environment.

Methods to automatically run program on Linux startup:

Automatically run program on Linux startup via systemd

systemd is the standard system and service manager in modern Linux. It is responsible for executing and managing programs during Linux startup, among many other things. Compatible programs will provide service unit files used by systemd to manage the program’s execution.

You can configure systemd to run programs automatically during Linux startup following these steps:

You’ll have to create your own service unit if it’s a custom program or if your program doesn’t come with one during installation
Related: Creating and modifying systemd unit files

Читайте также:  Как создать виртуальный диск windows 10 daemon tools

enabled service unit is executed during boot

Automatically run program on Linux startup via cron

cron is a daemon to execute scheduled commands. The commands are stored in the cron job table or crontab and are unique for each user in the system. It’s started during system boot either by systemd or System V init, and you can schedule your job or program to be executed right during the system boot itself by following these steps:

You’re required to select an editor for the crontab if this is the first time the user uses the command.

A crontab will be created for the user running the command and will be executed using the privileges of the user. If you need your program to run as the root user, run crontab -e as the root user itself.

@reboot defines the job to be executed during system boot.

Use full path for your programs when possible and write your commands in a single line.

The file is saved in /var/spool/crontab/

Automatically run program on Linux startup via rc.local

rc.local is a legacy from the System V init system. It is the last script to be executed before proceeding to a login screen for the desktop environment or a login prompt at the terminal. It’s usually a Bash shell script, and you can run anything from the script.

You can configure your rc.local script following these steps:

It must start with interpreter (/bin/bash) and ends with an exit code (0 is for success)

The file will be executed as the root user during system boot

Automatically run program on GNOME startup

GNOME is the default desktop environment for Linux distributions such as Ubuntu and Red Hat. GNOME can be configured to run programs when a user logs in and can be configured by following the below article:

Automatically run program on KDE startup

KDE is another popular desktop environment for Linux and is the default in Kubuntu and openSUSE. It can easily be configured to run programs when a user logs in as detailed in the following article:

Automatically run program on new Bash session

A new shell program will be spawned when you start your terminal session. Bash is the default shell for most Linuxdistributions, and when started, it will look for the following files in the particular order and executes them.

These files contains commands and logics to set up proper environment variables and run required programs in Bash language. It’s also configured to normally execute other files such as /etc/bashrc, /etc/bash.bashrc and

You can edit any of these files to run your program when a Bash session is started. Below is a part of a typical

Comment anonymously. Login not required.

Источник

6 Ways to Open a Ubuntu Application

Open your apps the most convenient way for you

In this guide, you will discover a number of different ways to open an application using Ubuntu. Some of them will be obvious and some of them less so.

Not all applications appear in the launcher, and not all of them appear in the Dash. Even if they do appear in the Dash, you might find it easier to open them in other ways.

You might want to make sure Ubuntu is updated so you don’t have any issues opening applications.

Use the Ubuntu Launcher to Open Applications

The Ubuntu Launcher is on the left side of the screen and contains icons for the most commonly used applications.

  • You can open one of these applications simply by selecting it.
  • Right-clicking​ on an icon often provides other options such as opening a new browser window or opening a new spreadsheet.
Читайте также:  Посмотреть открытые порты windows server 2012 r2

Search the Activities to Find an Application

If the application doesn’t appear in the launcher the second quickest way to find an application is to use the GNOME Activities menu.

  1. Select Activities in the upper left corner of your screen.
  2. Your screen will darken to display the Activities Overview. Here, you’ll see any applications that you have minimized, the other available workspaces, and a search.
  3. Type the name of the application you want into the search. GNOME will show you both the apps installed on your system and the ones available for download.

For a more advanced approach of finding a program, or if you can’t find your application in the Activities search, check out our breakdown of how to use the ‘which’ command to find a program.

Browse the Applications Menu to Find an Application

If you just want to see which applications are on your computer or you know the type of application but not its name you can simply browse the GNOME applications menu.

  1. To browse, select the Show Applications icon on the launcher or press the Super Key + A.
  2. The GNOME applications menu will open up, displaying all the apps you have in your system in alphabetical order. At the bottom, you’ll find the option to toggle between All applications and your Frequent ones.
  3. Select an app icon to launch it.

Use the Run Command to Open an Application

If you know the name of the application you can open it quite quickly in the following way:

  1. Press Alt+F2 to bring up the run command window.
  2. Enter the name of the application. If you enter the name of a correct application then an icon will appear.
  3. You can run the application either by clicking on the icon or by pressing Return on the keyboard.

Use the Terminal to Run an Application

You can open an application by using the Linux terminal.

To open a terminal press Ctrl+Alt+T or follow this guide for more suggestions. If you know the program’s name you can simply type it into the terminal window. For example:

Of course, some applications aren’t graphical in nature. One example of this is apt-get, which is a command-line package manager.

When you get used to using apt-get you won’t want to use the graphical software manager anymore.

Use Keyboard Shortcuts to Open Applications

You can set up keyboard shortcuts to open applications with Ubuntu.

  1. To do so, open the applications menu, and search for Settings.
  2. Open the Settings app.
  3. When the window opens, locate and press Devices in the left side menu.
  4. Now, the menu will change to show device related options. Choose Keyboard Shortcuts.
  5. The main body of the window will display a huge list of current keyboard shortcuts.
  6. Scroll to the very bottom of the list, and select the Plus Sign (+) icon.
  7. Another smaller window will pop up. Enter a Name for your shortcut. For the Command, you can usually use the name of the app. Sometimes, that’s different. You can search for the path to it with which . For example: which firefox
  8. If you don’t know the name of the command at all, you can try:
    ls -lah /usr/bin | grep -i
  9. Then, press Set Shortcut to input the key combination. Press the combination of keys that you want to assign the shortcut to on your keyboard. Then, press Add in the upper right of the window to create your shortcut

When the launcher has been created you can set the keyboard shortcut in the same way as the other launchers.

Источник

Оцените статью