In Windows, services, tasks, and processes can be viewed using the task manager application. Similarly, in Ubuntu, you can view all the services using the command line. If you are a beginner or using ubuntu for general or personal use, you may not have felt the need to check the services. But, for developers and sysadmins running a server, it is important to check the services for security and stable running of the system.
Services are the background programs that run in the background for several reasons to run the system. They are responsible for how the system works. These processes or groups of processes are also called “daemons.” The default service manager in Ubuntu is systemd or system daemon, which has been used recently in most Linux distros. It was Init in the 1980s in the earlier versions of Ubuntu.
Various services are running, such as system, network, etc. System services such as corn jobs, syslog, process management, etc., are frequently monitored by developers and system admins. There are tons of services that can be viewed easily through some commands. Let’s discuss in detail different ways to list services in Ubuntu.
List services through command-line
You can check only running services rather than all mixed-up services and even have options to store them in a text file or print them. Initially, init was the service manager for Ubuntu. For init, the service command is used to list services that extract the data from /etc/init.d. But systemd is the default service manager where systemctl command is used to list services from systemd. systemctl stands for system control. Several other commands can be used to check the services in Ubuntu, but here we will stick with systemctl and service commands.
1. Systemctl command
Systemctl is a command-line utility that controls the systems and service manager. Using systemctl, you can monitor, view, edit, and delete unit files using the service manager. A unit file is a text file consisting of executing processes, what comes before and after that is to be run, and other details. You can also view services and interact with them through options such as start, stop, enable, disable, etc.
To list all the services, i.e., running, failed, stopped, etc., execute the following command in a terminal window:
systemctl
where
- UNIT:- services or processes which the systemd represents as units
- LOAD:- Shows whether the unit is loaded in the memory or not
- ACTIVE:- Shows whether the unit is active or inactive
- SUB:- Shows the current status of units
- DESCRIPTION:- Shows the description of units
To list all the units of type service, execute the following command:
systemctl list-units --type service --all
It will display all the services, i.e., running, active, loaded, stopped, inactive, failed
To list only running services, execute the following command:
systemctl --type service --state running
To list active services, change the state from running to active in the above command:
systemctl --type service --state active
To list all the inactive services, change the state to inactive and execute the following command:
systemctl --type service --state inactive
Similarly, change the state to “exited” for stopped services to view the stopped services.
systemctl --type service --state exited
2. service command
The service command is a command-line utility used to run a SystemV init script stored in /etc/init.d directory. Like the systemctl command, it can start, stop and restart services or daemons. It does not have many options, but at least we can start, stop, reload, and check the status of the services. All scripts should support at least the start and stop options.
To list all the services, execute the following command:
service --status-all
To list only the running services, execute the following command:
service --status-all | grep '\[ + \]'
To list the non-running services, execute the following command:
service --status-all | grep '\[ - \]'
The [+] is used for running services and [-] for stopped services by the status command.
To count the number of services, use the -c option with the grep command and execute the following command:
service --status-all | grep -c ''
List services from /etc/init.d
The service command extracts the data from /etc/init.d, so we can directly list the services from the /etc/init.d directory in folders. Execute the following command to list the services from the /etc/init.d directory:
ls -l /etc/init.d/*
Conclusion
So, we discussed ways to list services in Ubuntu using the command line. Apart from systemctl and service commands, other commands such as top, htop, etc., can be used to list services. If you liked the article or if we missed something, please let me know in the comment section below.