Sidratul Muntaha – Linux Hint https://linuxhint.com Exploring and Master Linux Ecosystem Wed, 10 Mar 2021 03:37:00 +0000 en-US hourly 1 https://wordpress.org/?v=5.6.2 Shebang Bash: Explained with Examples https://linuxhint.com/shebang-bash-explained-in-examples/ Fri, 05 Mar 2021 10:47:54 +0000 https://linuxhint.com/?p=92899 Bash is a command language interpreter. Many operating systems incorporate bash as the default command interpreter, especially most of the GNU/Linux systems. Bash scripting is a method of automating a set of commands that would otherwise be executed interactively one-by-one.

In this guide, check out what shebang bash is and how to use it.

Shebang Bash:

In bash scripting, Shebang is a way to declare what interpreter the operating system will use to parse the rest of the file. The Shebang is characterized by the set of characters “#!” (without quotes).

Here’s a quick breakdown of the Shebang interpreter directive.

#!<interpreter> [arguments]

For example, if a script is to be parsed using the Bash shell, then the Shebang interpreter directive would look like this.

#!/bin/bash

The Shebang interpreter directive has certain properties.

  • It must be the first line of the script.
  • It must start with a shebang (#!).
  • There may or may not be whitespace after the shebang (#!).
  • The interpreter will be the full path to a binary file.
  • There may or may not be interpreter arguments.

Here’s a shortlist of some of the most common Shebang interpreter directives.

  • #!/bin/bash: The script will be parsed using bash.
  • #!/usr/bin/python: The script will be parsed using the python binary.
  • #!/usr/bin/env perl: The script will be parsed using the perl executable. The location of the perl executable will be provided by the env command.

Using Shebang Bash:

Scripts can have no Shebang bash. Any such script will be parsed using the default interpreter. For example, bash is the default interpreter for bash and sh for zsh. While most of the UNIX/Linux systems have bash as the default, users have options to use others. In such a scenario, without declaring the interpreter, the script may not perform its preferred task.

There are two methods of using the Shebang directive to declare the interpreter. The first one is to declare the file path to the executable.

#!/bin/bash

Another method is to use the env utility to locate the executable.

#!/usr/bin/env bash

The benefit of using the env utility is, it will look for the executable under the $PATH environment variable of the current user. In this example, env will look for the bash. If there is more than one bash executable declared in the $PATH variable, then the first one will be used.

As mentioned, Shebang bash also supports executable arguments. For example, to use bash with debug mode, the Shebang interpreter directive would look like this.

#!/bin/bash -x

When it comes to using env for the Shebang bash, adding an executable argument requires using the “set” option. For example, the following one will use bash with debug mode enabled.

#!/usr/bin/env bash
$ set -x

Script Example:

We’ve discussed the basics of Shebang bash. It’s time to put it into practice. Let’s have a look at the implementation of Shebang bash.

Launch the text editor of your choice and type the following script:

$ #!/bin/sh
$ echo "hello_world_bash"

Save the file. To run the script, it has to be marked as an executable. Run the following command:

$ chmod +x <script>

Run the script:

$ ./<script>

Not very difficult, right? Now, let’s try using the different Shebang bash expressions. Try the ones given below:

$ #!/usr/bin/env bash
$ set -x
$ echo "hello_world_bash_debug"

Overriding the Shebang Bash:

While the Shebang bash defines the interpreter to use, in certain situations, you may want to use a different interpreter. It’s possible to override the script-defined interpreter by explicitly specifying the interpreter to the shell.

For example, have a look at the following script:

$ #!/bin/sh
$ echo "hello_world_sh"

By default, it would be run using sh. To run it using bash, use the following method:

$ <interpreter> <script>

Note that for normal use cases just using the default sh or bash interpreter is good enough and overriding is not relevant.

Final Thoughts:

Shebang bash is a very simple concept. For bash scripting, it’s very important to understand and implement it.

Interested more in Bash scripting? Check out this beginner’s guide on how to write a simple bash script.

Happy computing!

]]>
How to Enable Tab Groups in Google Chrome https://linuxhint.com/enable-tab-groups-google-chrome/ Sat, 27 Feb 2021 15:11:37 +0000 https://linuxhint.com/?p=92178 Are there too many tabs open in your browser? Are you using Google Chrome? Then Google Chrome offers the “Tab Groups” feature. It’s an interesting way of keeping your tabs organized. All the tabs under the same group are organized neatly, color-coded with proper labeling.

In this guide, check out how to enable the “Tab Groups” in Google Chrome.

Installing Google Chrome

Google Chrome is a free browser available for all the major platforms (Windows, Linux, and macOS). For Linux, Chrome is available as installable RPM (for SUSE Linux, Fedora/CentOS/RHEL, etc.) or DEB (Debian, Ubuntu, Linux Mint, Pop!_OS, etc.) packages. Follow this guide to install Chrome on Arch Linux.

Here, let’s have a brief look at how to install Chrome on some of the most popular Linux distros.

Grabbing the installation package
For Linux, Google officially releases installable RPM and DEB packages. Go to the Chrome download page.

For Debian, Ubuntu, Linux Mint, and similar distros download the DEB package.

For Fedora, CentOS, RHEL, SUSE Linux, and similar distros, download the RPM package.

Installing the package
All the DEB-based distros use APT as the package manager. To install the Chrome DEB package using APT, run the following command.

$ sudo apt install <path_to_chrome_deb>

In the case of RPM-based distros, various package managers are available. Here are some of the most common ones.

To install the RPM package on Fedora, CentOS, or RHEL, run either of the following commands.

$ sudo yum install <path_to_chrome_rpm>

$ sudo dnf install <path_to_chrome_rpm>

To install the RPM package on SUSE Linux and similar distros, run the following command.

$ sudo zypper install <path_to_chrome_rpm>

Install Chromium browser

The base source code of both Google Chrome and Chromium is maintained by the Chromium project. Chromium browser is the vanilla build from the source (along with some open-source tools, like media codecs).

Both browsers support the “Tab Groups” feature. Unlike Chrome, most distros offer Chromium browser from the default package repos. Just run the appropriate command according to your distro.

To install Chromium on Debian, Ubuntu, Linux Mint, and similar distros run the following command.

$ sudo apt install chromium-browser

To install Chromium on Fedora, CentOS/RHEL, and similar distros, run either of the following commands.

$ sudo yum install chromium

$ sudo dnf install chromium

To install Chromium on Arch Linux and similar distros, run the following command.

$ sudo pacman -S chromium

Chrome Tab Groups

Starting from Chrome 83, Google announced that “Tab Groups” would be enabled by default. As of the latest Chrome release (Chrome 88), there’s no way of disabling this feature. While it’s still possible in older versions, it’s strongly not recommended to use an older browser.

In the case of the Chromium browser, it’s possible to enable and disable manually

Enabling “Tab Groups”
The default behavior of both Chrome and Chromium is to have this feature enabled. The method described under this section is no longer available on Chrome. Thus, it only applies to Chromium.

Open a new tab and go to the following link.

$ chrome://flags

Search for the term “tab groups”.

It should highlight the option “Tab Groups”. If it wasn’t changed, it should be set to “Default”. To enable the feature, select “Enabled”.

Chrome/Chromium will ask for restarting the browser to take the changes into effect. Click “Relaunch” to restart. Alternatively, you can do it manually after saving all your works.

Using “Tab Groups”

Creating groups
To add a tab to a group, first, we need a group or more. To create a new group, right-click a target tab and select “Add tab to new group”.

You can set the group name and color for easy identification.

Adding tabs to a group
Assuming you have your groups set properly, let’s get started. Right-click on any other tab, go to “Add tab to group”, and select the desired group. The group color will colorize the tab.

To create a new out of the new tab, you’d want to select “New group”.

Removing a tab from a group
Sometimes, individual tabs need to be removed from a group. To remove a tab, go to the tab, right-click the tab, and select “Remove from group”. The tab will be removed from the group.

Removing groups
When a group is no longer necessary, keeping it around is redundant. Removing a group is a necessary action to keep the tabs in order.

To remove a group, right-click the group icon, and select “Close group”.

Disabling “Tab Groups”
While this action isn’t recommended, it’s possible to disable “Tab Groups” because of the utility it offers. Note that this feature only applies to the Chromium browser. In the case of Chrome, there’s no way of disabling it.

First, open a new tab, and go to the following link.

$ chrome://flags

Search for “team groups”. Under the “Tab Groups” option, select “Disabled”. Finally, click “Relaunch” to take the changes into effect.

Final thoughts

The “Tab Groups” feature is really awesome in keeping the tabs organized. Of course, it’s not the ultimate solution. It lacks some features, for example, group merging. Ultimately, it’s up to you to organize your tabs. The “Tabs Groups” is just a tool to make it easier.

Interested in more Chrome tricks? Check out how to use multiple profiles simultaneously on Google Chrome.

Happy computing!

]]>
Adding a New Disk Device to Fedora Linux https://linuxhint.com/add-new-disk-device-fedora-linux/ Wed, 24 Feb 2021 00:33:45 +0000 https://linuxhint.com/?p=91169 Storage is one of the cheapest IT commodities in today’s market. Running low on disk space? Just grab a brand new high-capacity storage device from the market. Need high-performance storage? Then grab a high-performance SSD.

After the device is connected, it should be recognized in the system. However, at the software level, it still requires some configuration to use it properly. In this guide, check out how to add a new disk device to Fedora Linux.

Disk precautions

When you connect the new device to the computer, assuming the unit is functional, it should be recognized by the BIOS. If not, then here are a few possibilities to look for.

  • Ensure that the device is connected properly. Often, that’s a major source of headache, especially with external storage devices.
  • While it’s uncommon, you may also have a dead device at hand.
  • Sometimes, certain storage devices aren’t supported by some computers. It’s dependent on multiple factors like brand, model, etc.

Finding the disk device

Finding the new drive using CLI

Assuming that the device is functional and connected properly, let’s get started.

In Linux, all the disk devices are assigned a unique device name that begins with “hd” or “sd”. For example, “/dev/sda” is the first device label, “/dev/sdb” is the second device label.

Launch the terminal, and run the following command. It should list all the connected disk devices.

$ ls -l /dev/sd*

As the output suggests, the disk “/dev/sda” has two partitions, “/dev/sda1” and “/dev/sda2”.

Now, connect the new storage device, and run the command again.

$ ls /dev/sd*

Here, the new disk “/dev/sdb” has a single partition “/dev/sdb1”. If the device had no partition, there’d be only “/dev/sdb” in the result.

Finding the new drive using GUI

If you prefer using GUI, then it’s suggested to use the GNOME Disks. It’s a part of the GNOME desktop.

An alternative tool is to use GParted. It’s one of the most powerful tools for managing disk devices. GParted can handle disk formatting, partitioning, UUIDs, and even data rescue. Install GParted right away.

$ sudo dnf install gparted

Launch GParted. To check the partitions of a certain disk, select it from the drop-down menu on the top-right corner.

Creating partitions

A partition in disk drives is a logical separation of the disk space. Depending on the disk space and partition table type, the number of partition varies. Generally, high-capacity disks are split into multiple partitions.

If the disk is already partitioned properly, then you may skip this part. Following this step will erase any existing data from the disk, ensuring that there’s nothing valuable stored.

Ensure that the disk isn’t in use. If any of the disk partitions are mounted, make sure to unmount them. Learn how to unmount partitions using umount command.

Creating a partition using CLI

Fdisk is a powerful tool for managing disk partitions. One major benefit of fdisk is, all the changes you make aren’t immediately applied to the disk. All the changes are stored in memory and only applied when you tell the fdisk to do so. Launch the fdisk tool in interactive mode for our target device.

$ sudo fdisk <device_label>

It’s an interactive mode with lots of options available. To see all the available options, enter “m”.

Enter “p” to print all the partitions in the current partition label. It’ll also report the partition table type (GPT/DOS/SGI/Sun).

If there’s no need for the partition table type to change, then proceed with deleting the partition. Enter “d” to prompt fdisk to delete the partition.

To change the partition type, enter “g” (GPT), “G” (SGI (IRIX)), “o” (DOS), or “s” (for SUN). In this case, I’m going to create a new empty GPT partition table.

Enter “w” to write the new partition table. Note that it’ll remove any existing partitions.

At this point, the fdisk will exit. The disk will contain all its free space. To make the space usable, it has to be partitioned. Re-launch fdisk for the disk.

$ sudo fdisk /dev/sdb

The device must contain a partition or more to use the available storage space. To create a partition, enter “n”.

Fdisk will ask for various information, for example, the partition number, first/last sector, partition size, etc. Unless there’s something custom necessary, hit “Enter”. Fdisk will use the default values and the entire disk space for the new partition.

To write the changes to the disk, enter “w”.

Creating a partition using GUI

GParted another powerful solution for managing disk devices. Launch GParted.

From the top-left corner, ensure that the correct device is selected.

If the disk has any partition mounted, performing any alteration is going to be problematic. Right-click the partition(s) and select “Unmount”.

If the partitioning is fine, then there’s no need to touch anything. If not, consider re-partitioning the drive. Right-click the partition(s) and select “Delete”.

To create a new partition, right-click the “unallocated” space, and select “New”.

Change the values as you see fit. For this demonstration, the entire disk space will be under a single partition.

To take the changes into effect, click the “Apply All Operations” button. All the changes will be written to the disk, so ensure that everything is configured properly.

Once the process is finished, GParted will show the following window.

Creating a filesystem

The disk is properly partitioned. The next step is to create a Linux filesystem on the partition so that the operating system can use the space for storing data.

Creating a filesystem using CLI

Depending on the desired filesystem type, the command to run will change. By default, it’s recommended to make an EXT3/EXT4 filesystem for the best experience. If the disk is a portable one and used cross-device, then FAT16/FAT32 filesystem is recommended. However, FAT16 and FAT32 filesystems have a fixed value of the highest single file size.

Determine the new partition label.

$ lsblk

In this demonstration, our target partition is “/dev/sdb1”. Note the mount point. Then, unmount the partition using the following command.

$ sudo umount -v <mount_point >

To format the partition, run the following command.

$ sudo mkfs -v -t <filesystem> <partition>

As for the filesystem, the mkfs tool supports the following values.

  • ext3
  • ext4
  • fat16
  • fat32
  • ntfs
  • apfs
  • hfs

Creating a filesystem using GUI

Launch GParted and select the target device. Right-click the partition, go to “Format to”, and select your desired filesystem.

Once selected, click the “Apply All Operations” button.

Mounting filesystem

Finally, the filesystem is ready to be used. It has to be mounted to be accessible from the operating system.

Mounting a filesystem using CLI

Here’s a guide on how to use the Linux mount command for mounting partitions. To mount our desired partition, first, create a directory. This directory will act as the mount point.

$ sudo mkdir -v /my_partition

Now, mount the partition to the mount point we just created.

$ sudo mount --source <partition> --target <mount_point>

Verify if the mounting was successful.

$ mount

Mounting a filesystem using GUI

While GParted is capable of mounting a partition, it won’t allow the action unless the partition is declared under “/etc/fstab”.

An alternative is to use the GNOME Disks utility. Launch GNOME Disks. From the left panel, navigate to the target device. Select the partition and click “Mount selected partition”. Disks will automatically create a mount point for the partition.

Final thoughts

This guide demonstrates adding a new disk device to Fedora. It isn’t anything difficult. It’s a slightly time-consuming process. The good news is, it’s mostly a one-time process. However, it’s common that you may need to perform these actions once again.

Happy computing!

]]>
How to Install Official Wallpaper Packs on Fedora? https://linuxhint.com/install-official-wallpaper-packs-on-fedora/ Mon, 22 Feb 2021 11:19:23 +0000 https://linuxhint.com/?p=90722

Wallpapers are great for improving the user experience of any operating system. In the case of Fedora, one of its iconic features is the wallpapers it comes with. Every single Fedora release gets its own set of wallpaper, and these are some of the most anticipated components of any of its releases.

In this guide, check out how to install official wallpaper packs on Fedora.

Fedora Official Wallpapers

Fedora releases wallpaper packs for all the supported desktop environments.

It’s also possible to install the official Fedora wallpapers of a different release. For example, if you’re running Fedora 33, you can enjoy wallpapers from releases before that, such as Fedora 32.

Identifying Wallpaper Packages

Identifying desktop environment

Launch a terminal, and run the following command. It’ll print the name of the desktop environment running on the system.

$ echo $DESKTOP_SESSION

Identifying Fedora official wallpaper packages

The wallpapers are directly available from the official Fedora repos. The package name of the official wallpapers has a certain pattern and looks something like this:

$ f<fedora_version>-backgrounds-<desktop_environment>

For example, this is the package name for the official Fedora wallpapers for Fedora 32 running on the XFCE desktop:

$ f32-backgrounds-xfce

In addition to that, there are also additional wallpapers that come with every Fedora release. These are the supplement backgrounds that are selected from the community, driven by the guidelines that the Fedora project outlines.

The supplement wallpapers also have a similar pattern for the package name. It looks something like this:

$ f<fedora_version>-backgrounds-extras-<desktop_environment>

For example, the supplement background package from Fedora 32 for the GNOME desktop would have the following package name:

$ f32-backgrounds-extras-gnome

For easier demonstration, Fedora also has all the wallpapers displayed on the Fedora project wiki.

Check out Fedora wiki on official wallpapers.

Installing Official Wallpaper Packages

Ready with the package name for your desired wallpapers? Launch a terminal and install the package right away. Fedora supports both YUM and DNF as package managers. Thankfully, both share similar ways of installing a new package.

Installing wallpaper packages using YUM

Let’s grab the Fedora 32 official wallpapers for the GNOME desktop along with the extras.

$ sudo yum install f32-backgrounds-gnome f32-backgrounds-extras-gnome

Installing wallpaper packages using DNF

Use the following DNF command to install the official wallpapers of Fedora 32 for the GNOME desktop with the extras.

$ sudo dnf install f32-backgrounds-gnome f32-backgrounds-extras-gnome

Changing Backgrounds

Now that the backgrounds are installed, it’s time to change the backgrounds to the new ones. In this section, I’ve demonstrated how to change the backgrounds for GNOME, Cinnamon, MATE, and Xfce desktop environments.

Changing backgrounds on GNOME

Right-click on the desktop and select “Change Background”.

This option is also available from Settings >> Background.

Changing backgrounds on KDE Plasma

Right-click on a space in the background, and select “Configure Desktop and Wallpaper”. Alternatively, use the keyboard shortcut “Alt + D, Alt + S”.

Changing backgrounds on Cinnamon

On Cinnamon desktop, right-click and select “Change Desktop Background”.

Alternatively, you can also search “background” from the menu.

Changing backgrounds on MATE

On the MATE desktop, right-click on any space and select “Change Desktop Background”.

Alternatively, use the “Application Finder” to launch “Appearance”.

Final Thoughts

This guide demonstrates how to personalize Fedora with wallpaper for a better user experience.

Keeping the system packages up-to-date is an important task. It keeps the system secure, free of bugs/glitches, better performing, and having access to all the latest features. Learn how to update a Fedora Linux system.

Happy computing!

]]>
How to Install Microsoft Teams on Fedora? https://linuxhint.com/install-microsoft-teams-fedora/ Thu, 18 Feb 2021 14:16:57 +0000 https://linuxhint.com/?p=90139 The success of a team is incredibly dependent on effective communication. Microsoft Teams is a powerful solution for that. It’s a team collaboration tool that includes everything in a single package. The service includes messaging, chats, video conferences, and file sharing. In addition, Teams also integrates seamlessly with other services like Git, CI/CD pipelines, etc.

One of the biggest benefits of Microsoft Teams is that it’s a cross-platform tool, available for both Windows and Linux. In this guide, we are going to check out how to install Microsoft Teams on Fedora.

Microsoft Teams on Fedora

Microsoft Teams is a cross-platform solution. The official clients are both Windows and Linux (Ubuntu, RHEL/CentOS/Fedora, and SUSE Linux) users. It’s also possible to enjoy the service directly from the web browser (without any dedicated client).

Fedora is an RPM-based distro. For easier installation, Microsoft Teams is directly available as an RPM package. Installing the RPM package will also configure the Microsoft Teams repo for YUM/DNF. This takes care of keeping the client up-to-date.

To use Microsoft Teams, it’s recommended to have a Microsoft account. Don’t have one? Click Sign up for a Microsoft account.

Installing Microsoft Teams RPM

The official RPM package for Microsoft Teams is available at the following FTP link:

$ https://packages.microsoft.com/yumrepos/ms-teams/

Download the latest version of Microsoft Teams RPM. Note that the “insiders” builds are the equivalent of “beta” releases, so it’s recommended to avoid those. At the time of writing this article, the latest version available is Teams v1.3.00.958-1.

$ wget https://packages.microsoft.com/yumrepos/ms-teams/teams-1.3.00.958-1.x86_64.rpm

Once the download is finished, use either YUM or DNF to install the RPM package. It’ll ensure that any dependency is taken care of.

To install the RPM package using YUM, run the following command:

$ sudo yum install teams-1.3.00.958-1.x86_64.rpm

To install the RPM package using DNF, run the following command:

$ sudo dnf install teams-1.3.00.958-1.x86_64.rpm

Using Microsoft Teams

The installation is complete. It’s time to start using Microsoft Teams. Now, launch the app.

The app will ask you to log into your account. Enter the credentials to gain access to the Teams’ main functionality.

If your account isn’t signed up for Microsoft Teams, then it will prompt you to sign up. Click “Sign up for Teams”.

It’ll open a link in the default browser. Click “Sign up for free” to start the process.

Enter the email address of your account. While Teams support different email service providers, it’s recommended to use your Microsoft account.

Teams will ask for the purpose of using the service. Here, I’m going with the “For work and organizations” option.

Teams will ask for the full name, company name, and country/region.

Teams should be ready to go! The browser tab will redirect you to the Teams client. If it doesn’t, then close the browser, and restart the client. You’ll have to re-login to your account.

Teams will open up the welcome page. From the drop-down menu, select the organization.

Voila! The Teams dashboard is ready!

As mentioned earlier, Teams can connect to various third-party services for easier team collaboration. To install various service integrations, check the “Apps” section.

Teams support voice/video calls among their members. To make a call, check out the “Calls” section.

Final thoughts

Microsoft Teams is a simple yet powerful service. While it’s demonstrated using the free version, it comes at a price for professional usage.

There are also other awesome tools for team collaboration. Slack is one of the most popular applications, so let’s check out some cool Slack alternative services.

Happy surfing!

]]>
How to Manage Startup Services with Systemd in Fedora https://linuxhint.com/manage-startup-services-systemd-fedora/ Mon, 08 Feb 2021 12:17:35 +0000 https://linuxhint.com/?p=89368 Systemd is a software suite that offers an array of system components for Linux systems that can perform service configuration and system behavior management. It consists of an init system, various tools for device management, network connection management, login management, and event logging.

In this guide, check out how to manage startup services with systemd in Fedora.

Systemd on Fedora

Over the traditional init systems (UNIX System V and BSD), systemd offers flexibility and improvements. This is why most of the modern Linux distros have embraced systemd. Fedora is no exception. A key benefit of systemd is because it’s almost like a standard; the commands demonstrated on this guide will also work on any other Linux system that uses systemd.

To ensure that your Fedora system has systemd, run the following command.

$ systemctl --version

The following command will also reveal the location of the systemd on the system.

$ whereis systemd

To find the location of systemctl, run the following command.

$ whereis systemctl

It’s possible to verify whether systemd is currently running.

$ ps -eaf | grep systemd

Managing services using systemd

To manage services, systemctl is an easy-to-use tool. For the most part, systemctl is what you’re going to use when it comes to service management.

List services
Generally, any Linux system has numerous services ongoing. It’s a hard task to keep all of them memorized. Thankfully, systemctl can list all the services on the system.

The following command will list all the services. It includes enabled, disabled, running, and stopped services.

$ systemctl list-units --type=service --all

It’s possible to list services based on their state.

$ systemctl list-units --state=<state>

To list services based on multiple states, use the following command structure.

$ systemctl list-units --state=<state_1>,<state_2>

Here’s a quick list of all the available service states.

  • active
  • inactive
  • activating
  • deactivating
  • failed
  • not-found
  • dead

If you’re interested in “loaded”, “enabled”, “disabled”, and “installed” service files, then it requires the “list-unit-files” command instead. Run the following command.

$ systemctl list-unit-files --type=service

Checking service status
Before performing any action on a service, it’s a good idea to check the target service’s status. The following command will report the status of a service.

$ systemctl status <service>

Alternatively, use the following “service” command.

$ service <service> status

Starting a service
To start a service, run the following command.

$ sudo systemctl start <service>

Alternatively, the following “service” command will do the same task.

$ sudo service <service> start

Stopping a service
To stop a running service, use the following command.

$ sudo systemctl stop <service>

Alternatively, use the following “service” command.

$ sudo service <service> stop

Restarting a service
After making changes, a service requires a restart to put the changes into effect. To restart a service, run the following command.

$ sudo systemctl restart <service>

Alternatively, use the following “service” command.

$ sudo service <service> restart

Reloading a service
In the case of some services, those can load the new configuration without a restart. If that’s the case, then reloading is the better action. To reload a service, use the following command.

$ sudo systemctl reload <service>

Restart and reload
In case you’re not sure whether to restart or reload the service, then issue the “reload-or-restart” command. It’ll reload the configuration files in-place (if available). Otherwise, it’ll restart the service.

$ sudo systemctl reload-or-restart <service>

Enabling and disabling service
Based on whether the service starts at boot, there are two types of services.

  • enabled: The service will start automatically when the system boots.
  • disabled: The service won’t start when the system boots.

Note that any “disabled” service has to be started manually after the system boots.

To enable a service, run the following systemctl command.

$ sudo systemctl enable <service>

To disable a service, run the following systemctl command.

$ sudo systemctl disable <service>

Analyzing boot time
When booting, each service requires time to load completely. To determine how much time services spend during boot, run the following command.

$ systemd-analyze blame

Using systemd-analyze, you can also analyze the critical chain at boot. Run the following command to see the report.

$ systemd-analyze critical-chain

Final thoughts

Systemd makes it easy to manage startup services. This guide only demonstrates some of the simplest methods of manipulating services on Fedora.

However, systemd is more than that. In essence, systemd is the father of all other processes. To understand systemd on a deeper level, check out this guide on how systemd starts the system.

Happy computing!

]]>
How to Install Google Fonts on Fedora https://linuxhint.com/install-google-fonts-fedora/ Mon, 08 Feb 2021 11:08:11 +0000 https://linuxhint.com/?p=89160 Launched back in 2010, Google Fonts is a library of thousands of free licensed font families. It also provides APIs to incorporate the fonts via CSS and Android. For anyone looking for a new font to beautify their works, be it a document or a banner on GIMP, Google Fonts is an excellent place to start looking for.

In this guide, check out how to install Google Fonts on Fedora.

Installing Google Fonts on Fedora

There are multiple ways of installing Google Fonts on Fedora. The default and recommended method are to use the package manager to do the job. This way, the fonts are easier to manage.

It’s also possible to install the fonts manually. However, it may make the font management a bit more complicated.

Let’s get started!

Install Google Fonts using DNF

For Fedora, the RPM Fusion repository hosts all the Google Fonts as an installable package. This way, we can use DNF to manage the Google Fonts package for us.

By default, Fedora doesn’t have the RPM Fusion repo configured. It’s very simple to configure RPM Fusion. Learn more about how to set up RPM Fusion on Fedora.

For a quick review, the following DNF command will automatically install the appropriate RPM Fusion repo configuration packages.

$ sudo dnf install \
$ https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \
$ https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Tell DNF to check for updates available. As a new repo is added, DNF will automatically update the repo cache.

$ sudo dnf check-update

Now, we need the package name for the target Google font(s). Using the DNF search utility and grep filtering, we can list all the available Google font packages.

$ dnf search fonts | grep google

Finally, install the desired Google font package.

$ sudo dnf install <google_font_package>

Voila! The Google font is ready to be used! If your target application doesn’t recognize the font, restart the app to take the changes into effect.

Install Google Fonts manually

This method describes how to manually download and install Google Fonts without the help of any package manager.

First, grab the Google Fonts of your choice. Check out Google Fonts. You can download multiple fonts if necessary For demonstration, I’ve chosen Potta One. To download the font, click “Download family” from the top-right corner.

It’ll download the font in a zip archive. From this point on, we’ll be using the command-line interface. Launch a terminal, change the current directory, and extract the zip archive.

$ unzip <zip_archive>

Now, make a copy of the TTF file to the system font’s directory.

$ sudo cp -v <font>.ttf /usr/share/fonts

Verify if the copy was successful.

$ ls /usr/share/fonts

To take the changes into effect, rebuild the font cache. The system will automatically notice the change and incorporate the new font(s).

$ sudo fc-cache -v

Finally, restart the target application where you’re going to use the fonts.

Final thoughts

Google Fonts is an incredible service. It offers tons of fonts to customize your documents. This guide demonstrated how to install Google Fonts on Fedora.

If you’re interested in fonts, then you’re probably also working heavy-duty with text editors. Check out some of the best multi-platform text editors.

Happy computing!

]]>
How to Update a Fedora Linux System https://linuxhint.com/update-fedora-linux-system/ Wed, 03 Feb 2021 04:16:57 +0000 https://linuxhint.com/?p=88610 No matter whatever distro you’re using, it’s important to keep all the packages up-to-date. Package updates contain various improvements, bug fixes, security patches, and new/improved features.

In this guide, check out how to update the Fedora Linux system.

Updating Fedora

Fedora is an RPM-based Linux distro that’s maintained by the Fedora Project. Fedora acts as the testing ground for future releases of Red Hat Enterprise Linux. While Fedora is open-source software, RHEL isn’t. However, both share the same base.

Fedora is suitable for all sorts of usage. It can be used either for general-purpose use, server, workstation, and others. Fedora receives updates regularly.

Depending on the UI, there are two ways of updating Fedora: GUI and CLI.

Update Fedora using GUI

By default, Fedora comes with the GNOME desktop. One major feature of the GNOME desktop is, it also comes with a bunch of powerful tools. The following method demonstrates how to update Fedora using the GNOME Software tool.

Launch GNOME Software. It’s a GUI tool for easier package and repository management.

Go to the “Updates” tab. If there’s any update available to any package, it’ll show up here. To recheck for any available update, click the refresh icon at the top-left corner.

To install updates, click the “Download” button. The action will require root privilege.

Voila! All the packages are updated!

Update Fedora using CLI

Fedora is easier to keep updated using the package managers it comes with. Fedora supports both DNF and YUM package managers. However, it’s recommended to use DNF because it’s an upgrade over the traditional YUM.

Update Fedora using YUM

Launch the terminal. While this first step is optional, it may help to fix certain problems related to updating packages. Clean the local YUM repo cache.

$ sudo yum clean all

The following YUM command will check for any available updates. If the cache were cleaned previously, it’d rebuild the cache as well.

$ sudo yum check-update

If there’s any update available, run the following command to install them all.

$ sudo yum update

Alternatively, to update only the selected package(s), use the following command structure.

$ sudo yum update <package_1> <package_2>

Update Fedora using DNF

DNF is the default package manager that Fedora incorporates. It solves many of the problems that YUM had (memory inefficiency, slower performance, etc.) while delivering almost the same user experience.

Using DNF to update is almost similar to using YUM. Launch a terminal and clean the DNF cache. It’s an optional task.

$ sudo dnf clean all

Check if there’s any update available. If the cache was cleaned, then DNF will rebuild the cache automatically.

$ sudo dnf check-update

If any package update is available, the following DNF command will install all of them.

$ sudo dnf update

Alternatively, to update specific packages, use the following command structure.

$ sudo dnf update <package_1> <package_2>

Upgrading Fedora

When there’s a new version of Fedora available, installing it without completely reinstalling the entire operating system is possible. Note that this process may take quite a while. It’s always recommended to back up your important data, especially those located in the system directories.

Ready? Let’s get started! We’ll be using the DNF package manager to do the job.

First, check if all the currently installed packages are up-to-date.

$ sudo dnf upgrade --refresh

To upgrade the system, DNF requires a system upgrade plugin. Install the system upgrade plugin for DNF.

$ sudo dnf install dnf-plugin-system-upgrade

The next step is to download the system upgrade. Double-check the Fedora system version you’re upgrading to. Check out the latest version of Fedora.

$ sudo system-upgrade download --refresh --releasever=<target_fedora_version>

Finally, reboot the system to finish the upgrade process.

$ sudo dnf system-upgrade reboot

Final thoughts

Keeping Fedora updated is an easy task. Depending on your comfort, follow the method that meets the need.

Interested to learn more about the Fedora package managers? Check out how to use the DNF package manager. The guide is on CentOS, but the same commands and methods apply to Fedora as well.

Happy computing.

]]>
How to reset Ubuntu’s forgotten password https://linuxhint.com/reset-ubuntus-forgotten-password/ Wed, 03 Feb 2021 03:50:47 +0000 https://linuxhint.com/?p=88938 If you’ve ever lost your password, you’re not the only one. It’s definitely one of the most popular issues with tech support that people have throughout the years. The good thing is that, due to a forgotten password, you do not have to reinstall the whole operating system. In Ubuntu, they have made it extremely easy to restore your password. In VMware, single or dual boot, the methods listed here work to restore the Ubuntu password, and you’ll be able to restore your login credentials within minutes.

Let’s start by demonstrating Ubuntu Password Reset from Recovery Mode.

Booting into Ubuntu recovery mode:

Turn on your computer system and go to the grub menu. Mostly it appears immediately, but if that doesn’t happen, press escape or hold the shift key down until it appears. While working on VM-ware or VirtualBox, when the Oracle or VM-ware logo appears, you have to press the shift key. GRUB menu will be prompted to your screen, here select “Advance Options for Ubuntu“.

Now an option will be displayed, select it to go to the recovery mode:

You will see a black screen with a flash showing multiple lines of data. Here, wait for some time.

Root shell prompt:

You will be provided with numerous recovery mode options here. Select the one named “Root – Drop to Root Shell Prompt” from the given options. Press enter, and you’re all set.

You’ll see that there is an option to enter commands at the bottom when you choose the root shell prompt option. This is the prompt for your shell, and here you will be doing some magic to restore your forgotten password.

Remount root filesystem with write access:

By default, the root partition has given read-only privileges. But here you have to provide root and write access too. To remount it with write permission, use the following command:

ubuntu@ubuntu:~$ mount -rw -o remount /

Reset username or password:

List the available users using the following command once you will be provided with the root access :

ubuntu@ubuntu:~$ ls /home

Or you can see the available users by displaying the contents of /etc/passwd file using the following command:

ubuntu@ubuntu:~$ cat /etc/passwd

From the usernames accessible, select the one for which you’d prefer to reset the password. Now, reset the password for the chosen username by typing the following command:

ubuntu@ubuntu:~$ passwd  <user>

Enter new UNIX password:

It will ask you for a new password. Type the new password once and then again to confirm it:

ubuntu@ubuntu:~$ Retype new UNIX password:

You have restored your password successfully. Enter the Exit command for exiting the root shell.

ubuntu@ubuntu:~$ exit

On entering exit command, we will prompt back to the Recover Boot menu. Now, choose the standard boot option on the screen. There will be an alert about compatibility with the graphics mode. You don’t have to worry about it. A reboot will solve all these compatibility issues. Now we just have to log in with the password we just have set.

Possible Error:

    You may be encountered with Authentication token manipulation error when entering the new password:

    The cause for this error is that it is still mounted with Read-Only access. To overcome this, just type the command for remounting the file system and modify the access.

    Change the password once again. It will work now without displaying any errors.

Alternate method for resetting the password:

If you have trouble changing the password via root shell for some reason, you should follow these steps:

Step 1

Get the computer rebooted. To bring up the grub screen, hold the shift key for some time. To edit the Grub panel, click E.

Step 2

From the given set of lines, find any line starting with “Linux” using the up and down arrow keys and change access from read-only to read-write by just replacing ro recovery nomodeset to rw init=/bin/bash.

Step 3

To save the changes and to boot, press ctrl-x. You are now booting with both read and write access into a Linux kernel, here you can use the bash shell instead of GUI. In other words, a passwordless root shell will boot into your system.

Step 4

Type your username into the passwd command. If the username is unknown, search with the ‘ls /home’ or ‘cat /etc/passwd | grep -i bash’ command. Now reset the password and then exit the terminal. After it’s done, reboot using the following commands and you are good to go.

ubuntu@ubuntu:~$ reboot

ubuntu@ubuntu:~$ shutdown -r now

Conclusion:

Ubuntu’s root account will be locked as it does not have a root password by default. A user account you set up before installing Ubuntu is included as an administrator with sudo privileges. Yet, in any capacity, it doesn’t imply that you are root. This absence of a root password is an intended feature of Ubuntu. “The boot menu for “Ubuntu Advanced Options” allows you to perform certain root-related functions from the “root shell prompt.” This is why you can reset the Ubuntu password from this method.

Question is If it’s this quick and easy to restore Ubuntu passwords, isn’t this a security risk? The major security threat is if someone breaks into your account from a different location through the internet. It’s not occurring here. In case that some malicious entity has physical access to your computer system, its security is already at extreme risk. Well, if you want not to have this feature, you can disable it by encrypting your Hard Drive via LUKS encryption while installing Ubuntu.

]]>
How to Offline Update Fedora Workstation? https://linuxhint.com/offline-update-fedora-workstation/ Wed, 03 Feb 2021 01:40:28 +0000 https://linuxhint.com/?p=88963 Keeping the operating system up-to-date is important as updates contain bugfixes, performance improvements, security patches, and others. In the case of Linux, keeping the system updated mostly means keeping all the installed packages up-to-date.

Offline updating is an interesting concept when a system needs to be updated but without any reliable internet connection. In such a situation, the update packages are manually downloaded from a different source and applied to the offline machine.

In this guide, check out how to offline update the Fedora workstation.

Offline update Fedora

Fedora is a modern-day Linux distro with robust package management. Thanks to its package managers (DNF and YUM), it’s possible to update Fedora without any internet connection. However, for the best possible experience, the offline machine may have to be connected to the internet for a brief period of time.

It’s strongly recommended to use the CLI for updating Fedora offline.

Grabbing the Package Update List

The first step is to determine which packages have updates available. For this step only, it’s necessary to have an internet connection to the system.

Package update list using YUM:

The following YUM command will list all the packages that have updates available.

$ yum repoquery --upgrade --queryformat '%{name}.%{arch}'

For the next step, we need this list exported to a text file.

$ yum repoquery --upgrade --queryformat '%{name}.%{arch}' > update_list.txt

Package update list using DNF:

The following DNF command will list all the packages that have updates available.

$ dnf repoquery --upgrade --queryformat '%{name}.%{arch}'

Export the list to a text file.

$ dnf repoquery --upgrade --queryformat '%{name}.%{arch}' > update_list.txt

Package list using RPM:

If an internet connection isn’t available, then an alternative strategy is to grab the list of all the installed packages and work with it. Of course, this method will significantly increase the length of the process. It’s not recommended and follow only if you have to.

Grab all the installed packages in a nice format.

$ rpm -qa --queryformat "%{NAME}\n"

Export this list to a text file.

$ rpm -qa --queryformat "%{NAME}\n" > update_list.txt

Downloading Packages

Now, it’s time to download the desired packages. Export the text file containing the list of packages to download, load it on a different Fedora machine, and follow any of the following methods to download them.

First, check whether the text file contains only the package list, and nothing else.

$ vim update_list.txt

Download update packages using YUM:

The following YUM command will download the packages listed on the text file and store them in the directory specified. To avoid any issue related to dependencies, use the “–resolve” flag.

$ yum download --resolve $(cat update_list.txt) --downloaddir="<directory>
"

Download update packages using DNF:

Similar to YUM, the following DNF command will download and store all the packages (and dependencies) on the specific directory.

$ dnf download --resolve $(cat update_list.txt) --downloaddir="<directory>"

Installing the Updates

Finally, it’s time to update the offline machine. Export the update packages to the offline system and follow either of the following methods to install the RPM packages.

Install updates using YUM:

The following command will install all the RPM packages using YUM.

$ sudo yum install /<path_to_rpm>/*.rpm

Install updates using DNF:

The following command will install all the RPM packages using DNF.

$ sudo dnf install /<path_to_rpm>/*.rpm

Final Thoughts

It’s a complete guide on how to offline update Fedora workstation. This method will work on any modern version of Fedora, and it’s not a difficult task at all.

The only downside to this approach is the time and effort it requires. While the manual task is minimal, the most time-consuming part is downloading and installing all those RPM packages (especially if the list is too long).

Happy computing!

]]>
How to Setup and Use YUM on Fedora? https://linuxhint.com/setup-and-use-yum-on-fedora/ Sun, 31 Jan 2021 09:57:55 +0000 https://linuxhint.com/?p=88496

A Linux distro can be described as a collection of inter-dependent packages on top of the Linux kernel. Together, they offer an amazing experience. To keep the packages in order, a package manager is a must-have for every distro.

In the case of Fedora, YUM and DNF are two package managers. In this guide, we’ll check out how to set up and use YUM on Fedora.

YUM on Fedora

YUM is the primary package manager for Fedora that can query info about packages, fetch packages from repos, install/uninstall packages with automatic dependency solution, and update the entire system. YUM can also work with additional repos or package sources. To extend the functionality, YUM also supports many plugins.

YUM can perform the same tasks as RPM but in a more efficient and simpler manner. It also simplifies configuring your own repositories and RPM packages.

In the modern-day, YUM is being replaced by DNF, a modern-day package manager. It’s because YUM has some inherent issues like poor performance, high memory consumption, poor documentation, etc. However, it’s still worth learning YUM because Fedora, CentOS, and RHEL still support YUM as a valid package manager.

Installing YUM on Fedora

As one of the default package managers, YUM should come pre-installed with Fedora. Run the following commands to verify if YUM is installed:

$ which yum

$ yum --version

If YUM isn’t installed, then the following command will install YUM right away.

$ sudo dnf install yum

Using YUM

It’s time to learn how to use YUM– a full-fledged package manager with tons of features. This section demonstrates some of its most common and important commands.

Installing a package

To install a package, YUM requires the package name. Assuming you have the package name, run the following command to install it. YUM will automatically resolve and install all the necessary dependencies.

$ sudo yum install <package_name>

If there needs to install multiple packages, then just place all the package names separated by space.

$ sudo yum install <package_1> <package_2>

When installing any package, YUM will ask for confirmation. If you want YUM to install the packages without asking any permission, then use the “-y” flag.

$ sudo yum -y install <package_1> <package_2>

Install an RPM package

Various packages are directly available as RPM packages. While the default method of installing an RPM package is using the RPM tool, it’s recommended to use YUM to do so. If installed using YUM, the RPM package will be installed with all its dependencies (if available).

$ sudo yum install <rpm_package_path>

If there are multiple packages, then mention those as well.

$ sudo yum install <rpm_package_1> <rpm_package_2>

It’s also possible to install an RPM package that’s available through a direct link. In the following example, YUM will download and install the RPM Fusion repo.

$ sudo yum install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Removing a package

When a package is no longer needed, keeping it installed is redundant. To remove an unwanted package, use the following command structure:

$ sudo yum remove <package_name>

YUM will ask for permission to perform the action. If you want YUM to not ask for permission, use the “-y” flag.

$ sudo yum -y remove <package_name>

Same as installing multiple packages, YUM can also remove multiple packages.

$ sudo yum remove <package_1> <package_2>

Searching a package

In many situations, the exact package name for a certain app is hard to keep track of. In such situations, the built-in searching feature of YUM comes really handy.

To search for a certain package name with a search term, use the following command structure:

$ yum search <search_term>

Updating a package

If there’s an update available for a certain package, it’s possible to individually update the package. By default, YUM will download and install the latest version of the package with dependencies.

$ sudo yum update <package_name>

Updating system

Instead of updating individual packages, it’s more efficient to let YUM update the entire system. YUM will check and download all the available updates and install them accordingly.

First, check if there’s any update available.

$ sudo yum check-update

If there’s any update available, the following command will install all of them:

$ sudo dnf update

List packages

Using the “list” function, YUM can print all the list of packages, installed or available. This function can also search for an available package with a specific name.

To list all the installed packages, run the following command. The output will be huge, so we’ll be piping the output to “less” for easier browsing.

$ yum list installed | less

To list all the matching packages with a specific search term, use the following command:

$ yum list <search_term>

To list all the packages (installed and available), run the following command:

$ yum list all | less

Information about a package

Before installation, YUM can show detailed info about a package, and it can be helpful in various situations. To check info about a package, run the following YUM command:

$ yum info <package_name>

Group packages

In Linux, a group is a bundle of a number of packages. A group will generally contain packages that are related to each other. For example, the group “Java Development” contains all the necessary tools for developing programs in the Java programming language.

The following command will list all the available groups.

$ yum grouplist

To check the information about a group, run the following command:

$ yum groupinfo <group>

To install a group, run the following command:

$ sudo yum groupinstall <group>

If a group is to be updated, run the following command:

$ sudo yum groupupdate <group>

To uninstall a group, run the following command:

$ sudo yum groupremove <group>

Repositories

YUM repositories are the primary sources for downloading and installing packages. Fedora comes with the Fedora repos by default. However, it’s possible to add/remove additional repositories.

First, check out all the currently active repositories.

$ yum repolist

If there are some disabled repos, those won’t show on this list. To list all the repositories, run the following command:

$ yum repolist all

To install a specific package from a specific repo, use the flag “–enablerepo”. It works on both enabled or disabled repo.

$ sudo yum --enablerepo=<repo> install <package>

Cleaning up YUM

YUM generates all the repo package data in the “/var/cache/yum” location; each repo with its own sub-directory. While the cache is important for YUM to provide the fastest possible performance, a corrupted cache may be a problem, and cleaning it up will solve the issue.

$ sudo yum clean all

Now, perform a system update. YUM will automatically generate the caches again.

$ sudo yum check-update

Final thoughts

YUM is a powerful package manager. This guide demonstrates some of the most common usages of YUM. For quick help, check out the YUM help page.

$ yum --help

For in-depth information about YUM, the man page is quite useful.

$ man yum

Happy computing!

]]>
How to Set up RPM Fusion on Fedora Linux? https://linuxhint.com/set-up-rpm-fusion-on-fedora-linux/ Wed, 27 Jan 2021 12:56:18 +0000 https://linuxhint.com/?p=87696 Any Linux distro can be described as a combination of the Linux kernel and various packages on top. The system devs have to decide which packages can be available from the official repositories. Fedora is no different. It follows a set of rules when it comes to supporting packages through the official Fedora repos:

  • The package contents can’t be proprietary.
  • The package can’t be legally encumbered.
  • The package can’t violate the laws of the United States (especially Federal or applicable state laws).

This is where third-party repositories come into play. These repos have more freedom to provide software packages that Fedora excludes.

In this guide, check out how to set up RPM Fusion on Fedora Linux.

Fedora and RPM Fusion

RPM Fusion is one of the most popular third-party repos for Fedora, CentOS/RHEL, and similar distros. It’s often the primary source of many third-party applications for Fedora. RPM Fusion is a result of three projects merging: Dribble, Freshrpms, and Livna. Check out RPM Fusion.
All the packages from RPM Fusion are pre-compiled and available for all the current versions of Fedora, RHEL, and derivatives. RPM Fusion works with tools like YUM, DNF, and PackageKit. In the case of Fedora, YUM, and DNF are both available.

There are two different repos under RPM Fusion:

  • RPM Fusion free: It contains open-source software.
  • RPM Fusion non-free: It contains software without having an open-source licensing, but the source code is available for free.

There are also additional third-party repos for Fedora, for example, Google Chrome repo.

Configuring RPM Fusion

RPM Fusion is quite simple to configure, and it’s possible to do via both GUI and CLI.

Configure RPM Fusion using GUI

RPM Fusion offers direct RPM packages to configure the repos. Go to the RPM Fusion configuration page and download the RPM packages for both “free” and “non-free” repos.

Once downloaded, launch the file manager and browse for the RPM packages. Double-click the RPM packages. It’ll open them in GNOME Software.

Click “Install” to install the RPM package. It’ll require sudo privilege to act.

Finally, check if the RPM Fusion repos are enabled. Go to GNOME Software >> “Software Repositories”. If disabled, enable them. The actions will require sudo privilege to perform.

Voila! RPM Fusion is successfully installed and effective!

Configure RPM Fusion using CLI

RPM Fusion is easier to configure using the command-line. All it requires is running a single-line command to install the repository RPMs.

The following command will install RPM Fusion in both “free” and “non-free” repos. DNF will automatically grab and install the appropriate RPM packages for the Fedora version currently running.

$ sudo dnf install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

RPM Fusion should be enabled by default. The next step is to update the DNF cache. Run the following command:

$ sudo dnf update

If you’re using the GNOME/KDE desktop, the following step is recommended. It enables RPM Fusion integration with GNOME Software and KDE Discover.

$ sudo dnf groupupdate core

Disabling and enabling RPM Fusion

When a repo isn’t necessary, it’s generally better to disable the repo. A disabled repo will still remain configured in the system, but it won’t be used for installing or searching packages.

To disable RPM Fusion repo, run the following commands:

$ sudo dnf config-manager --set-disabled rpmfusion-free
$ sudo dnf config-manager --set-disabled rpmfusion-nonfree

If RPM Fusion is necessary once again, then enable the repos using the following commands:

$ sudo dnf config-manager --set-enabled rpmfusion-free

$ sudo dnf config-manager --set-enabled rpmfusion-nonfree

Removing RPM Fusion

Removing RPM Fusion from the system is simple. All it requires is to remove the RPM packages for both RPM Fusion “free” and “nonfree” repos.

First, determine the package name for the RPM Fusion repos.

$ rpm -qa | grep -i <repo>

Remove the packages using the following command:

$ sudo dnf remove <package_1> <package_2>

Final thoughts

RPM Fusion hosts tons of awesome software that aren’t available from the official Fedora/RHEL repos. After following this guide, hopefully, you’ve learned how to take advantage of this awesome repo.

Happy computing!

]]>
Installing Google Chrome on Fedora Linux https://linuxhint.com/install-google-chrome-fedora-linux/ Sun, 24 Jan 2021 23:05:15 +0000 https://linuxhint.com/?p=87564

Google Chrome is one of the top browsers for all platforms. It’s a product released by Google. The browser comes with numerous features, including synchronization with Google services, fast performance, fast performance, etc.

In this guide, check out how to install Google Chrome on Fedora Linux.

Google Chrome vs. Chromium

Chromium is often mentioned as the open-source alternative to Google Chrome. In action, both browsers feel and behave the same way. So, what’s the difference?

Both browsers share the same code baes. Chromium is an open-source browser project that’s maintained by the Chromium Projects. Google Chrome is based on Chromium. However, it comes with various proprietary features and different licensing.

For regular users, using either Chromium or Google Chrome will offer almost the same experience.

Installing Chrome and Chromium on Fedora

There are multiple ways of installing Google Chrome on Fedora. Google offers an installable RPM package of Chrome. Alternatively, you can manually enable the Google Chrome repo and install Chrome from there.

In the case of the Chromium browser, it’s directly available from the official Fedora repo. Some variations of the Chromium browser are also available from the RPM Fusion repository.

Install Google Chrome on Fedora

Install Chrome using GUI

This is the simplest way of installing the Chrome browser. However, it requires that you’re running the GNOME desktop. In the case of Fedora, GNOME is the default desktop environment.

Launch GNOME Software. It’s a graphical tool for managing Fedora repositories and apps.

First, it’s required to enable the Google Chrome repository. Go to “Software Repositories” on Software.

Click “Install” under the “Third Party Repositories.” It will enable all the important and popular third-party repos, including the one for Google Chrome.

For our purpose, we need the repo for Google Chrome. Enable the “google-chrome” repo. The action will require root privilege.

Once enabled, search for “chrome” on Software.

From the Google Chrome page, click “Install.”

Install Chrome using CLI

Google Chrome can also be installed from the command line. There are multiple ways to proceed. The recommended method of installing Chrome is to install it from the repo. Launch a terminal and install the extra Fedora repos.

$ sudo dnf install fedora-workstation-repositories

Although the repos are installed, they’re not activated. For this guide, we only need the Google Chrome repo. Enable the Chrome repo.

$ sudo dnf config-manager --set-enabled google-chrome

There are multiple releases of Google Chrome. The following command will install Google Chrome stable. This is the recommended way to go for most users.

$ sudo dnf install google-chrome-stable

To install the Chrome beta release, run the following command.

$ sudo dnf install google-chrome-beta

To install the Chrome unstable release, run the following command.

$ sudo dnf install google-chrome-unstable

Install Google Chrome from RPM

Because Chrome is a popular browser, Google officially offers an installable RPM package. Fedora users can manually download it from the official Chrome download page. Alternatively, DNF can download and install it.

The following DNF command will download and install Chrome from the official RPM package. Note that it’s the Chrome stable release.

$ sudo dnf install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

Install Chromium on Fedora

The Chromium browser is basically the vanilla version of Google Chrome. Because it’s open-source and comes with more flexible licensing, the Chromium browser may be the go-to choice. Moreover, it’s also suitable for security-concerned folks.

Configuring RPM Fusion

RPM Fusion is an awesome repo to have on Fedora. It’s a third-party repository that hosts numerous packages that Fedora or Red Hat doesn’t officially ship. All the packages of the repo are kept updated. The reason it’s recommended is that some flavor of Chromium browser comes from the RPM Fusion repo.

The following command will configure the RPM Fusion repo (free and non-free).

$ sudo dnf install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Install Chromium on GUI

Fire up GNOME Software and search for Chromium.

Make sure that the extra Fedora repos are installed and enabled, especially RPM Fusion ones.

Here, three different types of Chromium browser are available.

  • ungoogled-chromium: The official distribution of ungoogled-chromium. This variant retains the default Chromium experience as closely as possible. It incorporates tweaks for improved privacy, control, and transparency. However, the features must be manually activated/enabled.
  • Chromium (CBP): It’s a distribution of the ungoogled-chromium project on GitHub. It incorporates various tweaks for enhanced privacy, transparency, and control.
  • Chromium (Freeworld): The default Chromium browser built with all free world codecs and VA-API support.

Install the release of Chromium browser that suits your needs.

Install Chromium from CLI

As discussed earlier, there are several types of Chromium browsers available for Fedora. Those packages can also be installed from the command line.

Assuming the system already has RPM Fusion repos installed and enabled, the following DNF commands will install the Chromium browser release.

To install the vanilla Chromium browser, run the following command.

$ sudo dnf install chromium.x86_64

To install Chromium (CBP), run the following command.

$ sudo dnf install chromium-browser-privacy.x86_64

To install Chromium (Freeworld), run the following command.

$ sudo dnf install chromium-freeworld.x86_64

Fedora customization

For Chrome/Chromium browser, Fedora offers some recommended customization. It includes a custom user-agent string and access to many Fedora Project services. It’s an optional step to complete.

To install the Fedora-suggested configuration for Chrome/Chromium, run the following command.

$ sudo dnf install fedora-chromium-config.noarch

Final thoughts

Installing Google Chrome is a simple task. Follow the method that fits you best.

Happy computing!

]]>
How to Install OpenJDK on Fedora Linux https://linuxhint.com/install-openjdk-fedora-linux/ Wed, 20 Jan 2021 10:36:56 +0000 https://linuxhint.com/?p=86915 Java is a general-purpose programming language offering reliability, security, and compatibility. Java is everywhere – mobile apps, desktop programs, web applications, and enterprise systems.

To build Java apps, developers need the JDK (Java Development Kit) that comes with all the essential tools. In this guide, check out how to install OpenJDK on Fedora Linux.

JDK and OpenJDK

Before jumping into the OpenJDK installation process, here’s a quick refresh of JRE versus JDK.

JRE (Java Runtime Environment)

One of the key concepts that make Java awesome is “write once; run anywhere.” This is where JRE comes in.

When compiled, a Java program is transformed into bytecodes. It’s the job of the JRE to create a virtual environment in which this bytecode will run. The virtual environment is known as JVM (Java Virtual Machine).

As long as a platform has a JRE built for it, it’s possible to run Java apps.

For general users, having JRE installed is more than enough.

JDK (Java Development Kit)

The JDK is the software development environment for developing Java apps and applets. It’s a combination of multiple packages. The JDK includes the JRE, an interpreter, a compiler, a documentation generator, and other tools.

As the description suggests, JDK is necessary for developers working with Java.

There are multiple JDKs available to choose from – OpenJDK, Oracle JDK, AdoptOpenJDK, etc.

Oracle JDK vs. OpenJDK

Oracle maintains Java itself. Starting from Java 11, Oracle changed the Java licensing policy that caused quite a commotion in the community and market.

Previously, Oracle offered free updates (security patches, hotfixes, etc.) to the older Java (Oracle JDK) versions. These hotfixes would also be included in the OpenJDK codebase. Starting from Java 11, Oracle changed the Java release cycle and stopped offering patches to the old versions for free. If there was support necessary, then it requires purchasing a license from Oracle.

Moreover, Oracle JDK isn’t to be used for professional workload anymore. If Oracle JDK is to be used, then it also requires getting a license from Oracle. However, for educational and personal use, Oracle JDK is still available, free of charge.

Using OpenJDK offers more freedom. OpenJDK is more than enough for personal and educational use. If the older versions of OpenJDK to be used, it’s also fine. However, that comes with security concerns. Because of Oracle’s new release cycle, a new OpenJDK will also become obsolete very soon. For many businesses, that’s not a viable solution.

OpenJDK vs AdoptOpenJDK

This is where AdoptOpenJDK comes in. It’s a community release of the OpenJDK. It improvises where OpenJDK lacks.

In the case of OpenJDK, older Java comes with the threat of security issues. Those patches are only available on the latest Java. AdoptOpenJDK backports those improvements to the older versions, offering a more consistent experience for the businesses.

AdoptOpenJDK is also enterprise-ready. It’s sponsored by major powerhouses of the industry, namely Amazon, IBM, Microsoft, Red Hat, etc.

As for licensing, AdoptOpenJDK is also flexible. It uses an OpenJDK source that’s licensed under GPL v2 with Classpath Exception. The build scripts and other codes related to AdoptOpenJDK is licensed under Apache License v2.0. Check out AdoptOpenJDK to learn more.

For personal and educational purposes, either is fine.

Installing OpenJDK on Fedora

OpenJDK is an open-source implementation of the Java Standard Edition (Java SE) and JDK. It’s the source code of OpenJDK that builds the basis of all the commercial Java products, including Oracle JDK. OpenJDK is publicly available under the GNU General Public License.

The OpenJDK package is directly available from the official Fedora repo. It contains all the major Java versions. At the time of writing this article, OpenJDK is available for Java 8, Java 11 (LTS), and Java 15 (latest).

To get a list of all the available OpenJDK versions, run the following command.

$ dnf search openjdk

It’s recommended to go with the long-term release. In this example, the following command will install Java 11, the latest LTS release. There

$ sudo dnf install java-11-openjdk-devel.x86_64

To install the latest Java, run the following command. Note that this command applies to any latest Java release. As of now, the latest Java version is Java 15.

$ sudo dnf install java-latest-openjdk-devel.x86_64

Verify the installation.

$ java -version

$ javac -version

Install AdoptOpenJDK

While the default OpenJDK is fine, AdoptOpenJDK offers more features and flexibility for everyone. There are two ways to install AdoptOpenJDK.

Install AdoptOpenJDK from the archive

First, grab the appropriate version of AdoptOpenJDK. Check out AdoptOpenJDK latest releases page.

Extract the archive.

$ tar -xvf OpenJDK11U-jdk_x64_linux_hotspot_11.0.9.1_1.tar.gz

Add the location of the newly extracted directory to “PATH.” To make it a permanent change, add the line to bashrc.

$ nano ~/.bashrc
$ export PATH=/home/viktor/Downloads/jdk-11.0.9.1+1/bin:$PATH

Verify that the installation was successful.

$ java -version
$ javac -version

Install AdoptOpenJDK RPM

This is the recommended way of installing AdoptOpenJDK. Instead of manual installation, it’s better to let the package manager do the job.

Downloading the RPM package for Fedora is not intuitive. First, go to the link that hosts AdoptOpenJDK RPM packages for Fedora.

Select the current version of Fedora your system is currently running. In my case, it’s Fedora 33.

Go to the “x86_64” folder.

As we’re interested in grabbing the RPM package, select the “Packages” folder.

Download the AdoptOpenJDK RPM package of your choice. The packages are named after their Java version, JVM type, etc. As we’re going for the JDK, skip grabbing any JRE package.

Once downloaded, install the RPM package.

$ sudo dnf localinstall adoptopenjdk-11-hotspot-11.0.9+11.2-3.x86_64.rpm

Install AdoptOpenJDK using SDKMAN

SDKMAN is an interesting solution to manage parallel versions of multiple SDKs. It’s a tool that’s designed for UNIX-based systems. It offers a convenient CLI and API for installing, switching, removing, and listing SDKs.

Besides JDK, SDKMAN supports tons of SDKs. Check out SDKMAN supported SDKs.

Installing SDKMAN is quite simple. Just run the following command.

$ curl -s "https://get.sdkman.io" | bash

Follow the on-screen instructions to complete the installation. Once finished, restart the terminal and run the following command to load SDKMAN.

$ source "$HOME/.sdkman/bin/sdkman-init.sh"

Verify that SDKMAN is successfully installed.

$ sdk version

The following command will list all the available JDKs that can be installed using SDKMAN.

$ sdk list java

In my case, the following command will install AdoptOpenJDK 11 (LTS).

$ sdk install java 11.0.9.hs-adpt

SDKMAN will ask whether to set it for default. If there’s no other version installed, then SDKMAN will set it as the default.

For more in-depth use of SDKMAN, check out the official SDKMAN usage guide.

Final thoughts

Installing JDK is a must for those interested in working with Java. Follow the method that suits you the best.

New to Java programming? Here’s a quick list of Java tutorials for you to get started.

Happy computing!

]]>
Installing Steam on Fedora Linux https://linuxhint.com/install-steam-fedora-linux/ Tue, 19 Jan 2021 18:29:33 +0000 https://linuxhint.com/?p=85947

Steam is one of the largest marketplaces for gaming. It hosts thousands of games from publishers all over the world. If you’ve ever been into gaming, then Steam is definitely a name you’ve heard.

In addition to the awesome online marketplace, Steam also offers a dedicated client for easier management of games. For Linux, however, Steam is more than that. Steam is the leading platform for supporting Linux as a viable gaming platform. Thanks to Steam client and Proton, a big portion of Steam games can run on Linux.

In this guide, check out how to install Steam on Fedora Linux.

Steam on Fedora Linux

Steam offers an official desktop client for multiple platforms, including Windows, Linux, macOS, etc. By default, Steam offers a DEB package for Debian/Ubuntu-based systems. For Fedora, however, the installation is a bit different.

Install Steam from RPM Fusion repo

RPM Fusion is a 3rd-party repository for apps that Red Hat and Fedora Project don’t ship. The software comes in pre-compiled RPM packages for all current Fedora versions and RHEL or clone versions. RPM Fusion works with YUM, DNF, and PackageKit, etc.

Note that Steam for RPM Fusion is available only for 32-bit architecture. However, it should work fine under Fedora 64-bit system.

Configuring RPM Fusion is quite simple. Just run this long command.

$ sudo dnf install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Now, update the DNF cache.

$ sudo dnf update

Finally, install Steam.

$ sudo dnf install steam

Install Steam flatpak

Flatpak is an interesting type of Linux package. Given the support for the platform, a flatpak package can run on any Linux distro. All it requires is having the flatpak package manager installed. Steam is available as a flatpak package. This method is less troublesome than the previous one.

The flatpak package manager comes pre-installed with Fedora. So, there’s no need to install it again manually. However, if it’s missing, then run the following command to install it quickly.

$ sudo dnf install flatpak

Add the FlatHub repo to flatpak. FlatHub is basically the official flatpak app store.

$ sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

Finally, install Steam flatpak.

$ sudo flatpak install flathub com.valvesoftware.Steam

Configuring Steam

Once the client is installed, it’s time to configure it. Launch the Steam client.

When launched for the first time, Steam will download the latest updates. It may take some time.

Steam is ready to go! Assuming you already have a Steam account, select “LOGIN TO AN EXISTING ACCOUNT”. If there’s no Steam account, then click “CREATE NEW ACCOUNT” and follow the instructions to create a new one.

Enter the necessary credentials.

Voila! Steam is up and running!

Configuring Proton

Proton is a powerful tool released by Valve Software (owner of Steam). It’s integrated with the Steam client. It’s the tool that offers to have a better experience playing Windows games on Linux. Under the hood, Proton is a combination of multiple tools like Wine and DXVK. It’s all installed and maintained automatically.

There’s also a big database to find out whether your desired game is stable under Proton. Check out ProtonDB.

To enable Proton, go to Steam >> Settings.

From the “Settings” window, select “Steam Play” from the left panel.

Check the options marked in the screenshot. As for the Proton version, ensure that it’s the latest version.

Steam will prompt for restarting the client. Select “RESTART STEAM” to take the changes into effect.

Uninstalling Steam

If for some reason, Steam is no longer required, you may want to uninstall it. Depending on the installation method, the uninstallation procedure will vary.

If Steam was installed from the RPM Fusion repo, then DNF can do the job.

$ sudo dnf remove steam

If Steam was installed as flatpak, then use the following command instead.

$ sudo flatpak uninstall com.valvesoftware.Steam

To further clean up the Steam residue files and directories, run the following commands.

$ cd ~/.local/share && rm -rf Steam

Final thoughts

Installing Steam is not a difficult task at all. Enjoy all your favorite games from Steam.

If you’re into gaming, there are some dedicated Linux distros out there. Check out some of the best Linux distros for gaming.

Happy computing!

]]>
How to Check Version and Update Fedora Linux Kernel https://linuxhint.com/check-version-update-fedora-linux-kernel/ Wed, 13 Jan 2021 23:32:19 +0000 https://linuxhint.com/?p=85610 For any operating system, the kernel is at the core. Linux is the kernel, rather than the entire operating system, of any Linux distribution. The kernel is responsible for interacting between the hardware of the computer and the software.

The Linux kernel is regularly updated to offer the best possible experience. This guide shows you how to check the version and update the kernel of Fedora.

Fedora Linux

Fedora is a well-known Linux distribution that is free for all users. This is the distribution that comprises the base of the Red Hat Enterprise Linux. While Fedora is primarily sponsored by Red Hat, thousands of other developers contribute to the project that was eventually incorporated into RHEL (after testing and quality assurance processes).

Basically, Fedora is the upstream, community distribution of RHEL. However, Fedora is also a solid distribution for general use, workstations, servers, containers, and others.

Check Fedora Linux Kernel Version

Checking the current kernel version will determine whether there is an update available.

There are multiple tools available to check the current version of the kernel.

uname

The uname command is a powerful tool for printing system information, including information about the kernel. There are two parameters to reveal kernel information.

The following command will print the kernel version of the running kernel.

$ uname -r

The kernel version can be broken into the following format.

$ <major_version>-<minor_version>-<release>.<architecture>

To check the kernel release time, use the following command.

$ uname -v

neofetch

The neofetch tool is similar to uname. It is also a lightweight tool used for revealing system information. The reason I like neofetch is because of its clean and colorized output.

Neofetch is not a tool that comes pre-installed on Fedora. Thankfully, neofetch is directly available from the Fedora software repo. Install neofetch using the dnf command.

$ sudo dnf install neofetch

Launch neofetch. The kernel version is located under the “Kernel” entry.

rpm

The primary job of the rpm tool is to install and manage RPM packages. Fedora installs kernels as RPM packages. Thanks to this, we can use rpm to list all the installed kernel versions.

$ rpm -q kernel

hostnamectl

The hostnamectl command is a tool used for managing the hostname of the system. However, the hostnamectl command can also print system information, including the kernel.

Run the hostnamectl command to report a summary of system information, along with the kernel version.

$ hostnamectl

grubby

The grubby command is a tool used for configuring bootloader menu entries. However, the grubby command can also be used to display the kernel version.

Run the following grubby command to print the location of the default kernel that loaded during boot.

$ sudo grubby --default-kernel

To get further in-depth information about the kernel, use the –info flag followed by the kernel location.

$ grubby --info <kernel>

/proc/version

The content in this file describes system information. It also contains information about the kernel version.

$ cat /proc/version

Updating Fedora Linux Kernel

Fedora manages all system package updates via the DNF package manager. In the case of the kernel, it is no different. It is strongly recommended to update the kernel through DNF.

Update Kernel through System Update

The best way to update the kernel of your system is to run a system update. DNF will search for any available updates for all installed packages (including the kernel) and update to the latest version (if available). To update all installed packages, run the following DNF command.

$ sudo dnf update

Update Kernel Only

It is also possible to update the kernel only. In Fedora, the kernel is managed under the package name kernel. Note that it features only the latest stable kernel. Check out the Linux Kernel Archives for all the available kernel packages.

Before performing the update, check out the kernel package information via the following command.

$ dnf info kernel

There are also other kernel packages offered by Fedora. Here is a quick list of the package names and what they contain. These packages may be relevant in various scenarios; for example, debugging, building kernel modules, etc.

  • kernel: The default package that contains the kernel for single, multi-core, and multi-processor systems.
  • kernel-debug: Contains a kernel with numerous debugging options enabled; great for debugging but comes at the cost of system performance.
  • kernel-devel: Contains kernel headers and makefiles to build modules against the kernel package.
  • kernel-debug-devel: The development version of the kernel that comes with numerous debugging options enabled; suitable for debugging but comes at the cost of system performance.
  • kernel-headers: Contains the C header files that specify the interface between the Linux kernel and user-space libraries and apps. These header files define various structures and constants that are crucial for building most standard programs.
  • linux-firmware: Contains all the Linux firmware files necessary to run various devices.
    perf: Contains necessary scripts and documentation of the ‘perf’ tool that comes with each kernel image sub-package.
  • kernel-abi-whitelists: Contains information related to the Fedora kernel ABI; includes a list of kernel symbols that are necessary by external Linux kernel modules and contains a DNF plugin to enforce the rule.
  • kernel-tools: Contains various tools and documentation for manipulating the Linux kernel.

To update to the latest kernel, run the following DNF command, which automatically installs the most suitable kernel version for your system.

$ sudo dnf install kernel --best

To take the changes into effect, reboot the system. Otherwise, your system will continue running on the older kernel.

$ sudo reboot

Configuring the Default Kernel

If multiple versions of the kernel are installed, then one kernel will become the default version that is loaded when the system boots. It is also possible to configure an alternate version of the kernel to be used as the default kernel.

The following command will print the default kernel.

$ sudo grubby --default-kernel

Next, issue the following command to list all the installed kernels, which will also print all the GRUB menu entries for all the kernels.

$ sudo grubby --info=ALL

To set a different kernel as the default kernel, take a note of the kernel location from the previous step and apply this location in the following command. In this case, I have set /boot/vmlinuz-5.8.15-301.fc33.x86_64 as the default kernel, instead of /boot/vmlinuz-5.9.16-200.fc33.x86_64.

$ sudo grubby --set-default <kernel>

Reboot the system to take the changes into effect.

Final Thoughts

Updating the kernel is no longer a difficult task. By default, Fedora offers a pre-compiled kernel that is general-purpose and suitable for the most part.

It is possible to manually build the Linux kernel from source. However, this can be quite a tedious process and takes some time to perform. In certain situations, building and deploying a custom kernel may offer advantages over using the default kernel. Learn more about how to compile a Linux kernel here.

Happy computing!

]]>
How to Make Backgrounds Transparent in GIMP https://linuxhint.com/make-backgrounds-transparent-gimp/ Thu, 07 Jan 2021 19:01:05 +0000 https://linuxhint.com/?p=84815 When it comes to image editing, Photoshop is the first name that comes to mind. However, while Photoshop is a powerful and popular photo editor, it can be complicated and difficult to use for regular users. GIMP offers an excellent free alternative to Photoshop. Granted, GIMP is also a bit more complicated than conventional image editors, but not any more than Photoshop.

This article shows you how to make the background of an image transparent in GIMP.

Making an Image Transparent in GIMP

How do you make the background of an image transparent? This can be achieved by removing the background of the image and keeping only the necessary elements in the forefront. In image editing, removing the background of an image is one of the most common actions you will perform.

When the background is transparent, it takes the color and details of the new image. For example, putting a transparent image on top of a yellow image will have a yellow background.

Removing a Solid-Color Background

If the target image has a solid-colored background, then removing the background will be easier.

For this demonstration, I have created the following image. The image is quite simplistic. It contains two circles, one inside the other, on top of a flat-colored background.

Load the image in GIMP.

Next, add an alpha channel. To add this channel, go to Layer >> Transparency >> Add Alpha Channel.

The change should be visible under the Layer tab.

Now, it is time to select the background. GIMP offers two tools for selecting the background: the Color tool and the Fuzzy Select tool. In this method, we will select the Color tool from the left sidebar. Alternatively, you can use the Shift + O keyboard shortcut to open this tool.

Now, click on the background. GIMP will mark the entire background that matches the selected color. This selection will be highlighted.

Once the background has been highlighted, it is now time to delete it. To delete the selected area, go to Edit >> Clear. Alternatively, use the keyboard shortcut Delete.

And, voilà! The background has been removed successfully! Finish the process by un-marking the selected area. Go to Select >> None. Alternatively, press the Ctrl + Shift + A keyboard shortcut.

Removing a Multi-Colored Background

In the previous step, the target image was a simple geometric design with a flat-color background. What if the background were something more complex? For example, when taking a selfie, the background is not a flat color. Removing the background in such an image would not work with the previous method.

In principle, the task of removing the background will be the same. You will identify the area of the image that you want to retain, select the area that you want to remove, and remove the background by deleting it. In this section, however, the selection tools will differ.

Load the target image in GIMP. As in the previous example, I will use the same simple I created for the demonstration.

Add an alpha channel to the image.

We will use the Path tool to select the area to retain. Using this tool, you can outline the image portion that will remain intact. While using this tool, you click on the image and drag the cursor to outline the image you want to keep. The clicked point is marked with a dot, and all the dots generated are connected to mark the area. Because of this, the marking may or may not be as smooth as intended. The more vertices that are used, the smoother the marking will be.

Once you are finished marking the image, press Enter to end the marking process, and the entire object will be selected.

We have selected the part we want to keep, and now, we must invert the selection. This way, GIMP will select all the remaining portions to delete. In this case, the deleted portion will be the background. To invert the selected portion, go to Select >> Invert. Alternatively, use the Ctrl + I keyboard shortcut.

Now, we will simply remove the contents of the selection. Go to Edit >> Clear. Alternatively, use the Delete keyboard shortcut.

Voilà! The background has now been removed successfully!

Saving the Image

Once the background of the image has been removed, it is now time to save the transparent image. To export the transparent image as a different image, go to File >> Export As. Alternatively, use the Shift + Ctrl + E keyboard shortcut.

As for the file type, change the extension of the filename (GIMP automatically converts and saves in the format).

Final Thoughts

Removing the background of an image can be a simple task with GIMP. Learning the tools involved in this process does not take much time. The only issue is the time it takes to outline your selection. Any high-quality background removal, especially with a complex background, will require quite a lot of time.

GIMP not your jam? Worry not. There are more awesome alternatives to Photoshop that you can run on Linux. Check out the best Photoshop alternatives on Linux here.

Happy computing!

]]>
How to Use AWK on Linux https://linuxhint.com/use_awk_linux/ Wed, 06 Jan 2021 03:21:01 +0000 https://linuxhint.com/?p=84543

The utilities Linux offer often follow the UNIX philosophy of design. Any tool should be small, use plain text for I/O, and operate in a modular manner. Thanks to the legacy, we have some of the finest text processing functionalities with the help of tools like sed and awk.

In Linux, the awk tool comes pre-installed on all Linux distros. AWK itself is a programming language. The AWK tool is just an interpreter of the AWK programming language. In this guide, check out how to use AWK on Linux.

AWK usage

The AWK tool is most useful when texts are organized in a predictable format. It’s quite good at parsing and manipulating tabular data. It operates on a line-by-line basis, on the entire text file.

The default behavior of awk is to use whitespaces (spaces, tabs, etc.) for separating fields. Thankfully, many of the configuration files on Linux follow this pattern.

Basic syntax

This is how the command structure of awk looks like.

$ awk '/<search_pattern>/ { <action_on_match>; <another_action>; }' <file>

The portions of the command are quite self-explanatory. Awk can operate without the search or action portion. If nothing is specified, then the default action on the match will be just printing. Basically, awk will print all the matches found on the file.

If there’s no search pattern specified, then awk will perform the specified actions on every single line of the file.

If both portions are given, then awk will use the pattern to determine whether the current line reflects it. If matched, then awk performs the action specified.

Note that awk can also work on redirected texts. This can be achieved by piping the contents of the command to awk to act on. Learn more about the Linux pipe command.

For demo purposes, here’s a sample text file. It contains 10 lines, 2 words per line.

$ cat sample.txt

Regular expression

One of the key features that make awk a powerful tool is the support of regular expression (regex, for short). A regular expression is a string that represents a certain pattern of characters.

Here’s a list of some of the most common regular expression syntaxes. These regex syntaxes aren’t just unique to awk. These are almost universal regex syntaxes, so mastering them will also help in other apps/programming that involves regular expression.

  • Basic characters: All the alphanumeric characters underscore (_) etc.
    • Character set: To make things easier, there are character groups in the regex. For example, uppercase (A-Z), lowercase (a-z), and numeric digits (0-9).
  • Meta-characters: These are characters that explain various ways to expand the ordinary characters.
    • Period (.): Any character match in the position is valid (except a newline).
    • Asterisk (*): Zero or more existences of the immediate character preceding it is valid.
    • Bracket ([]): The match is valid if, at the position, any of the characters from the bracket is matched. It can be combined with character sets.
    • Caret (^): The match will have to be at the start of the line.
    • Dollar ($): The match will have to be at the end of the line.
    • Backslash (\): If any meta-character has to be used in the literal sense.

Printing the text

To print all the contents of a text file, use the print command. In the case of the search pattern, there’s no pattern defined. So, awk prints all the lines.

$ awk '{print}' sample.txt

Here, “print” is an AWK command that prints the content of the input.

String search

AWK can perform a basic text search on the given text. In the pattern section, it has to be the text to find.

In the following command, awk will search for the text “quick” on all the lines of the file sample.txt.

$ awk '/quick/' sample.txt

Now, let’s use some regular expressions to further fine-tune the search. The following command will print all the lines that have “brown” at the beginning.

$ awk '/^brown/' sample.txt

How about finding something at the end of a line? The following command will print all the lines that have “quick” at the end.

$ awk '/quick$/' sample.txt

Wild card pattern

The next example is going to showcase the usage of the caret (.). Here, there can be any two characters before the character “e”.

$ awk '/..e/'  sample.txt

Wild card pattern (using asterisk)

What if there can be any number of characters at the location? To match for any possible character at the position, use the asterisk (*). Here, AWK will match all the lines that have any amount of characters after “the”.

$ awk '/the*/' sample.txt

Bracket expression

The following example is going to showcase how to use the bracket expression. Bracket expression tells that at the location, the match will be valid if it matches the set of characters enclosed by the brackets. For example, the following command will match “The” and “Tee” as valid matches.

$ awk '/T[he]e/' sample.txt

There are some predefined character sets in the regular expression. For example, the set of all uppercase letters is labeled as “A-Z”. In the following command, awk will match all the words that contain an uppercase letter.

$ awk '/[A-Z]/' sample.txt

Have a look at the following usage of character sets with bracket expression.

  • [0-9]: Indicates a single digit
  • [a-z]: Indicates a single lowercase letter
  • [A-Z]: Indicates a single uppercase letter
  • [a-zA-z]: Indicates a single letter
  • [a-zA-z 0-9]: Indicates a single character or digit.

Awk pre-defined variables

AWK comes with a bunch of pre-defined and automatic variables. These variables can make writing programs and scripts with AWK easier.

Here are some of the most common AWK variables that you’ll come across.

  • FILENAME: The filename of the current input file.
  • RS: The record separator. Because of the nature of AWK, it processes data one record at a time. Here, this variable specifies the delimiter used for splitting the data stream into records. By default, this value is the newline character.
  • NR: The current input record number. If the RS value is set to default, then this value will indicate the current input line number.
  • FS/OFS: The character(s) used as the field separator. Once read, AWK splits a record into different fields. The delimiter is defined by the value of FS. When printing, AWK rejoins all the fields. However, at this time, AWK uses the OFS separator instead of the FS separator. Generally, both FS and OFS are the same but not mandatory to be so.
  • NF: The number of fields in the current record. If the default value “whitespace” is used, then it’ll match the number of words in the current record.
  • ORS: The record separator for the output data. The default value is the newline character.

Let’s check them in action. The following command will use the NR variable to print line 2 to line 4 from sample.txt. AWK also supports logical operators like logical and (&&).

$ awk 'NR > 1 && NR < 5' sample.txt

To assign a specific value to an AWK variable, use the following structure.

$ awk '/<search_pattern>/ { <action_on_match>; <another_action>; }' <variable>=<value>, <input_file>

For example, to remove all the blank lines from the input file, change the value of RS to basically nothing. It’s a trick that uses an obscure POSIX rule. It specifies that if the value of RS is an empty string, then records are separated by a sequence that consists of a newline with one or more blank lines. In POSIX, a blank line with no content is completely empty. However, if the line contains whitespaces, then it’s not considered “blank”.

$ awk '{print}' RS='' sample.txt

Additional resources

AWK is a powerful tool with tons of features. While this guide covers a lot of them, it’s still just the basics. Mastering AWK will take more than just this. This guide should be a nice introduction to the tool.

If you really want to master the tool, then here are some additional resources you should check out.

Internet is quite a good place to learn something. There are plenty of awesome tutorials on AWK basics for very advanced users.

Final thought

Hopefully, this guide helped provide a good understanding of the AWK basics. While it may take a while, mastering AWK is extremely rewarding in terms of the power it bestows.

Happy computing!

]]>
GIMP: How to Resize Image? https://linuxhint.com/gimp-how-to-resize-image/ Sun, 03 Jan 2021 17:57:35 +0000 https://linuxhint.com/?p=84027

GIMP is a powerful image editor that’s free of charge and open-source. It’s a cross-platform tool that’s often compared to Adobe Photoshop. GIMP comes with tons of features and plugins to offer the finest image editing experience.

In this guide, check out how to resize an image using GIMP.

Resizing Image

While GIMP offers a ton of value and power, oftentimes, people find it difficult to operate. It’s understandable as GIMP isn’t the simplest image editor out there. While having tons of features is a boon, it also complicates things for novice users. However, once learned, GIMP is quite powerful.

In image editing, readjusting the dimensions of an image is a common task. For the most part, image resizing is necessary if it’s too large to fit the target job. For example, an image with 1920x1080px resolution needs to be scaled down for the thumbnail.

GIMP offers simple methods to resize an image to the desired dimension.

Resize the Image Using GIMP

GIMP is available for all the major Linux distros. If not installed, then install GIMP snap by running the following command.

Snaps are universal Linux packages that can be installed on any supported distro. Check out the official Snapcraft documentation on how to install snap.

$ sudo snap install gimp

For the demonstration, this image is grabbed from Unsplash. Check it out on Unsplash.

Fixed the image resize
Open the image in GIMP.

To change the image dimension, go to Image >> Scale Image.

When the dialog box opens up, enter the target image dimension. The link button signifies whether the aspect ratio will be locked/unlocked.

Click “Scale” to apply the change.

Free-hand image resize
What if there’s no necessity of resizing the image with precision? Then, we can perform a free-hand image resizing. Essentially, it will be dragging the image with a cursor to reshape it.

To do so, open the image in GIMP, and press “Shift + S”. This will start free-hand resizing. Similar to the prior method, make sure to lock/unlock the aspect ratio option.

To apply the changes, click “Scale”.

Saving the image
Once the change is applied, save the image. Go to File >> Save.

By default, GIMP will save the file in XCF format. Note that an XCF file created by a new version may not work on an older GIMP.

Exporting the image
To export the image in a more convenient format, go to File >> Export as. Alternatively, use the keyboard shortcut “Shift + Ctrl + E”.

In this example, to save the file in PNG format, change the file extension from the file name to “.PNG”. Click “Export” to proceed.

GIMP will ask what information to preserve. If not sure, then go with the default options. Click “Export” to finish the process.

Final thoughts

Resizing images using GIMP is quite a simple task. Follow the method that suits your needs.

In certain situations, instead of the whole image, only a part of it may be relevant. Check out how to crop images in GIMP.

Happy computing!

]]>
GIMP: How to Draw Circle https://linuxhint.com/gimp-draw-circle/ Sun, 03 Jan 2021 16:03:18 +0000 https://linuxhint.com/?p=83836

GIMP is a powerful software for image editing and related tasks. It comes with tons of basic and advanced features. Often, GIMP is compared to Adobe Photoshop as the FOSS alternative.

As an image editor, GIMP can work on existing images and draw an image from scratch. In this guide, check out how to draw a circle using GIMP.

Drawing a circle in GIMP

Drawing a circle is an essential task for any image editor. In GIMP, the “Ellipse selection” is the tool that will allow us to create a circle.

The very first step is to create a new image. From the GIMP main window, go to File >> Menu. Alternatively, we can use the keyboard shortcut “Ctrl + N”. If there needs a circle to be drawn on top of an existing image, create a new layer from Layer >> New Layer. Alternatively, use the keyboard shortcut “Shift + Ctrl + N”.

GIMP will ask for the image properties. It will come with the default values. Change them as necessary.

The image is created successfully.

Open the “Ellipse select” tool from Tools >> Selection Tools >> Ellipse Select. Alternatively, select it from the toolbox.

It’s time to draw the ellipse. Click and drag the cursor on the image and start drawing a circle. It’ll look something like this.

The border of the circle needs stroking to make it solid. To do so, go to Edit >> Stroke Selection.

It’ll open a dialog box, asking for the stroke properties. Click “Stroke” to apply the selection.

Need to work on the border while keeping the inside of the circle clean? Go to Select >> Border.

Select the border properties, especially the border width.

The result would look like this.

Filling the circle with color

This is an additional step and may not apply in all situations. In case you want to fill the circle with a specific color, then follow this method.

First, select the color from the color selection icon. For example, red is selected as the foreground color, and blue is selected as the background color. Select the right color for the background/foreground.

To fill the foreground of the circle, press “Ctrl + , (comma)”. To fill the background of the circle, press “Ctrl + . (dot)”.

Saving the picture

To export the picture, go to File >> Export As. Alternatively, use the keyboard shortcut “Shift + Ctrl + E”.

GIMP will ask for the location to save the file. As for the file format, change the file extension in the file name. GIMP will automatically recognize the change and save the file in the desired format.

Final thoughts

GIMP is an awesome tool for drawing images. However, it doesn’t offer you to create a perfect circle. Three’s only the option to draw an ellipse. The best one can do draw a near-perfect circle by hand. The dimension of the circle can be dragged and changed to a seemingly accurate circle. It may require some practice.

Not interested in GIMP? Worry not. There are lots of Photoshop alternatives that you can try. Check out best Photoshop alternatives on Linux.

Happy computing!

]]>
How to Run Traceroute in Linux https://linuxhint.com/run_traceroute_linux/ Fri, 01 Jan 2021 20:43:53 +0000 https://linuxhint.com/?p=83875

Traceroute is a tool in Linux that allows you to investigate the routes of network packets. It can help you in identifying the limiting factor of network packet journeys. Traceroute is also useful for troubleshooting sluggish network connections. This guide shows you how to run traceroute in Linux.

About traceroute

Traceroute works by sending packets of data to the target computer, server, or website and recording any intermediate steps through which the packets travel. The output of a traceroute command will be the IP addresses and domain names through which the packets pass. These entries also show how long it takes for the packets to reach each destination. This may explain why some websites may take longer to load than others, as the number of traffic hops can vary.

Traceroute is also useful for mapping local networks. Insight into the topology and connections of the local network is found when running the tool.

Note that while using traceroute, some devices may not interact well. This could be due to routers being bugged, ISPs rate-limiting ICMP messages, devices configured not to send ICMP packets (to prevent distributed DoS attacks), etc. Some networks are also configured to block traceroute requests.

Installing traceroute

Traceroute is a powerful tool that is available for all Linux distros. Provided below is a short list of the commands to install traceroute on various distributions.

For Debian/Ubuntu and derivatives:

$ sudo apt install traceroute -y

For Fedora and derivatives:

$ sudo dnf install traceroute

For openSUSE, SUSE Linux, and derivatives:

$ sudo zypper in traceroute

For Arch Linux and derivatives:

$ sudo pacman -S traceroute

Using traceroute

The following sections show you how to use traceroute on your Linux system.

Basic Usage

The primary method for using traceroute is quite simple. All traceroute requires is the destination to perform the probing. The destination can be either a domain or an IP address.

$ traceroute linuxhint.com

$ traceroute 8.8.8.8

If a network is configured to block the traceroute signal, then this probe will be denoted with asterisks.

IPv4 or IPv6

By default, traceroute will use the default Internet Protocol with which your system is configured. To manually set the IP version, follow the procedure below.

To tell traceroute to use IPv4, use the “-4” flag:

$ traceroute -4 linuxhint.com

To tell traceroute to use IPv6, use the “-6” flag:

$ traceroute -6 linuxhint.com

Testing Ports

If there is a need to test a specific port, the port can be specified using the “-p” flag. For UDP tracing, traceroute will start with the given value and increase with each probe. For ICMP tracing, the value will determine the initial ICMP sequence value. For TCP and others, this will be the constant destination port to connect.

$ traceroute -p <port> 192.168.0.1

Hiding Device Names

In some situations, the device names in the output may make the output look messy. For more clarity, you can hide the device names from the output. To do so, use the “-n” (no mapping) flag:

$ traceroute -n linuxhint.com

Traceroute Timeout Limit

By default, traceroute waits for 5 seconds to receive a response. In certain situations, you may want to change the waiting time to be greater or less than 5 seconds. To do so, use the “-w” flag. Note that the time value is a floating-point number.

$ traceroute -w 6.0 linuxhint.com

Probing Methods

There are multiple methods that you can use to probe the remote address. To specify traceroute to use ICMP echo, use the “-I” flag:

$ traceroute -I linuxhint.com

To use TCP SYN for probing, use the “-T” flag:

$ sudo traceroute -T linuxhint.com

Setting the Maximum Number of Hops

By default, traceroute will track 30 hops. Traceroute offers the ability to manually set the number of hops to track.

Use the “-m” flag with the number of hops:

$ traceroute -I -m 10 linuxhint.com

Specifying the Interface

If there are multiple network interfaces connected to the computer, then it may help to specify the network interface to use for sending packets. To specify the network interface, use the “-i” flag:

$ sudo traceroute -i enp0s3 linuxhint.com

Defining the Number of Queries for a Hop

To define the number of queries for a hop, specify this number using the “-q” flag:

$ traceroute -I -q 4 linuxhint.com

Routing Packets through a Gateway

To route packets through a certain gateway, use the “-g” option, followed by the gateway:

$ traceroute -I -g 192.168.0.1 linuxhint.com

Traceroute Help Page

The above demonstrations are just some of the common usages of traceroute, and there are even more features for you to use. To get quick help, open the traceroute help page with the following command:

$ traceroute --help

For a fuller, more in-depth guide on all the available traceroute options, check out the man page with the following command:

$ man traceroute

Conclusion

Traceroute is a powerful tool used for network diagnostics, and there are tons of options it supports. Mastering traceroute may require some time and practice. When using this tool, you will often employ the methods described in this article.

There are more tools like traceroute out there. If you are looking to work with a similar tool in GUI, then check out Zenmap to scan a network. Zenmap is a GUI front-end for another popular network scanner called Nmap.

Happy computing!

]]>
How to Find Text in Files in Linux https://linuxhint.com/find_text_in_files_linux/ Tue, 22 Dec 2020 13:20:54 +0000 https://linuxhint.com/?p=82471

For a system administrator, working with text files is a common phenomenon. Maybe need to find a specific section from piles of log files for troubleshooting something? Or, need to find the document that contains essential information quickly?

In the case of Linux, there are numerous methods to find texts in files. It’s possible using both built-in tools and 3rd-party apps. Check out how to find texts in files in Linux.

Finding text in files

Depending on the number of files you have to perform a search on, there are two ways to perform the text search: automated or manual. If you have to work with a couple of text files, the manual search is more suitable. However, if there are hundreds of text files, then the automated search is the most efficient.

For automated search, we’ll be using grep. Grep comes pre-installed on any Linux distro. As for manual search, any modern text editor will do the job.

Find text in files using grep

In Linux, grep is the default tool for searching texts. Its name is derived from the ed command g/re/p that stands for “globally search for a regular expression and print matching lines.” It’s available on any modern Linux distro.

Grep is a command-line tool. Its command structure is as follows.

$ grep <option> <regular_expression> <file_path>

As the name of grep suggests, the pattern to search for is described using a regular expression. The regular expression is a special type of string that describes a pattern to match, locate, and manage. To learn more about grep and regular expression, check out using grep and egrep with regular expression.

For demonstration purposes, grab a sample text file. In this example, download the GNU General Public License v3.0 text file.

Basic search

The fundamental way of using grep is to search for a basic string.

Take a look at the following grep command. It’ll search for the word “GNU” in the text file.

$ grep "GNU" gpl-3.0.txt

To show the line number, use the “-n” flag.

$ grep -n “GNU” gpl-3.0.txt

To perform a case-insensitive search using grep, use the “-i” flag.

$ grep -ni “gnu” gpl-3.0.txt

You may not want to see the search matches but only the file name where the match happened in some situations. To print only the filename, use the “-l” flag. Here, the asterisk denotes to use all the text files in the current directory.

$ grep -l “gnu” *

We can also pipe the output of other commands to grep.

$ cat gpl-3.0.txt | grep -n “GNU”

Regular expression

Regex offers a smart way of fine-tuning the search. It has its own rules. However, different applications and programming languages implement regular expression differently. Here are a couple of examples that you can use with grep.

To define that the string is to be found at starting a line, use the caret (^) symbol.

$ grep -n “^GNU” gpl-3.0.txt

To define that the string is to be found at the end of a line, use the dollar sign ($).

$ grep -n “to$” gpl-3.0.txt

To describe that there can be any character at a certain location of the pattern, use the period character (.). For example, the expression “G.U” is valid if there’s any character between “G” and “U”.

$ grep -n “G.U” gpl-3.0.txt

To describe that there can be a subset of characters at a particular location of the pattern, use the brackets ([]). For example, the expression “t[wo]o” tells that the match is valid for “two” and “too” only.

$ grep -n “t[wo]o” gpl-3.0.txt

Extended regular expression

As the name suggests, an extended regular expression can do more complex things than basic regular expressions. To use extended regular expression with grep, you have to use the “-E” flag.

$ grep -nE <extended_regex> <file>

To search for two different strings, use the OR operators (|).

$ grep -nE “GNU|General|License” gpl-3.0.txt

Finding text in files

Now comes the main part. Instead of manually telling grep the file to perform the search on, grep can do it automatically. In the following command, grep will use all the available text files in the current directory for searching the pattern.

$ grep <regex> *

If you want to grep to perform the search on a different directory, then you have to specify the location.

$ grep <regex> <directory_path>

If there are folders, grep doesn’t explore them by default. To tell grep to search recursively, use the “-R” flag.

$ grep -nR <regex> <directory_path>

Grep GUI

If you prefer to work with GUI but still want to enjoy grep’s features, then check out searchmonkey. It’s a front-end solution for grep. The package is available on almost all the major Linux distros.

Find text in files using nano

GNU Nano is a simple and powerful text editor that comes with any Linux distro. It has built-in features to search for text in a text file.

Note that in this method, you have to open the text file, and search manually. It’s doable if there’s only a handful of text files to work with. If there’s more, then using grep is the most optimal choice.

Open the text file in nano.

$ nano <file_path>

To search for a string match, press “Ctrl + W”. After typing the string to search for, press “Enter”.

Find text in files using Vim

Vim is a well-known and reputed text editor. It’s the command-line equivalent of a modern text editor. Vim comes with numerous advanced features like plugins, macros, auto-completion, filters, etc.

Similar to nano, Vim works with a single file at a time. If you have multiple text files, then using grep is the most optimal way to go.

To search in a text file, first, open it in Vim.

$ vim <file_path>

Enter the following Vim command and hit “Enter”.

$ :/<search_term>

Find text in files using GNOME Text Editor

The GNOME Text Editor is the text editor that comes with the GNOME desktop. It’s a simplistic text editor with all the basic features you’d expect. It’s a nice alternative to the command-line text editors.

Similar to nano and vim, the same caution applies to this method. If the number of text files is large, then you better stick with grep.

Open the text file in Text Editor. Press “Ctrl + F” to bring up the search bar.

Find text in files using VS Code

Visual Studio Code is a powerful text editor with tons of features. It’s optimized for programmers to be used as if it’s a full-fledged IDE. It’s available on almost all the major Linux distros.

Install the Visual Studio Code snap package.

$ sudo snap install code --classic

Open the text file in VS Code. Press “Ctrl + F” to start searching.

Final thoughts

There are numerous ways to search text in files. It’s an easy task to master. It’s strongly recommended to master the grep command because it offers the most value in terms of efficiency and ease-of-use.

If you prefer GUI, then there are numerous text editors to choose from. Any modern text editor will provide the text search option.

Happy computing!

]]>
How to Check CPU Utilization in Linux https://linuxhint.com/check-cpu-utilization-linux/ Mon, 14 Dec 2020 23:33:34 +0000 https://linuxhint.com/?p=81723 The performance of the CPU is one of the major determinants of the performance of a system. To ensure the most out of the limited processing power, it’s necessary to monitor how this resource is used. Monitoring the CPU performance can help debugging processes, managing system resources, taking system decisions, and evaluating systems in real-time.

In this guide, check out how to check CPU utilization in Linux.

CPU utilization in Linux

The CPU is the primary source of all the processing power a computer offers. To get the most out of it, it’s necessary to manage and optimize its usage.

Modern operating systems are optimized to use the CPU as efficiently as possible. Even other apps out there are quite optimized. However, users may not be. In my case, for example, I play games while there are hundreds of browser tabs open and multiple background tasks running. While all the software is optimized, my way of usage will cause a higher CPU load.

If multiple users are logged in, then the CPU usage will automatically be high. However, the system admin may want to keep an eye on it to ensure that someone isn’t hogging all of it, causing overall poor system performance and experience. If a certain process/app is causing too much CPU usage, it may either be malfunctioning, bugged or that’s the nature of it.

Sometimes, unusual CPU usage may also indicate that there’s a system intrusion.

Based on all this information, checking CPU utilization can be quite insightful.

Check CPU utilization in Linux

In the case of Linux, there are numerous tools to monitor CPU usage. It has various built-in system calls to extract performance readings. Some of the tools come pre-installed with all Linux distros, some may require manual installation.

All the following methods are demonstrated on Ubuntu 20.04.1 LTS. However, they’ll work just fine on any other modern distro.

Check CPU utilization using top

Using top, you can monitor the system in real-time. It reports a brief summary of system information along with a list of processes and threads currently being managed by the Linux kernel. It also offers interactive options to modify its behavior and perform various actions.

The top tool can show CPU utilization. Launch the tool.

$ top

Here, the key line to focus on is the third one. The output values are explained briefly. Each value explains the amount of time the CPU spends performing something.

  • us: Time spent running processes for people in the “user space”.
  • sy: Time spent running “kernel space” processes.
  • ni: Time spent running processes with custom (manually set) nice value.
  • id: Time spent idle.
  • wa: Time spent waiting for I/O request completion.
  • hi: Time spent servicing hardware interrupts.
  • si: Time spent servicing software interrupts.
  • st: Time lost for running virtual machine, also known as “steal time”.

Now, you can sort and filter the process list with various hotkeys. Here, I’ve described the ones that are associated with CPU usage.

  • P: Sort processes by CPU usage.
  • I: Remove idle processes from the list. To revert, press “I” again.
  • M: Sort the list by memory usage.
  • S: Sort the list by how long processes have been running.
  • U: Filter the processes by the owner.
  • K: Kill a process. Requires the PID of the process.

Check CPU utilization using htop

Htop and top both are essentially the same tools. They both offer the same features in terms of system monitoring capability. However, htop offers a better quality-of-life experience.

The default display of the htop is more comfortable to work with. The UI has better clarity than the top. The texts are colorized and pleasant to look at. It also offers both horizontal and vertical scrolling.

While most distros will have top installed by default, you have to install htop manually. It’s best to install htop using snap as it works on any Linux distro. Assuming you have snappy (the snap package manager) installed, run the following command.

$ sudo snap install htop

Launch htop.

$ htop

I’ll not discuss anything further as the usage of htop is the same as the top.

Check CPU utilization using iostat

The iostat tool reports CPU and I/O usage statistics. It’s a simple tool with simple output. However, it will only report the statistics of the moment the tool was run. Unlike top or htop, iostat doesn’t offer real-time system monitoring.

The iostat tool comes as a part of the sysstat package. It’s available on almost any Linux distro. Assuming you’ve installed the sysstat package, let’s move on.

Launch iostat.

$ iostat

Interested in a more in-depth report? Use the “-c” flag to see CPU usage of user processes, system processes, I/O wait, and idle time.

$ iostat -c

Use the flag “-x” for extended statistics. The flag “-t” will define how many times each report should be displayed.

$ iostat -xtc 5 2

Check CPU utilization using mpstat

The mpstat tool is a part of the sysstat package. The tool reports the usage of individual processors or processor cores.

To use mpstat, you have to have the sysstat package installed in your system. Assuming you already have the package installed, let’s move ahead.

Launch mpstat.

$ mpstat

Here’s what the values mean. Each value describes the CPU usage at a certain level.

  • %usr: User-level CPU usage.
  • %nice: CPU usage by “nice” user processes.
  • %sys: CPU usage by the kernel.
  • %iowait: Waiting for disk read/write.
  • %irq: Handling hardware interrupts.
  • %soft: Handling software interrupts.
  • %steal: Forced waiting for a hypervisor handling virtual processors.
  • %guest: Running a virtual processor.
  • %idle: Standing idle.

Check CPU utilization using sar

The sar command is for collecting and reporting system activity information. It offers a short and simple report about CPU utilization.

We can use sar to offer the CPU information at a certain interval (in seconds). While it’s not a real-time report, it’s still better to work with.

$ sar<interval_second>

In the last example, sar would run infinitely. We can define how many instances sar will print the output. In the following example, sar will print the output at 5 seconds interval, for 10 times.

$ sar 5 10

Check CPU utilization using vmstat

The vmstat tool reports various system information like system processes, memory, swap, CPU performance, and I/O.

Run vmstat. It’ll report the system information of the moment it was run.

$ vmstat

Similar to sar, vmstat can report the system status at a fixed interval (in seconds).

$ vmstat 3

In the last step, vmstat would run infinitely. To run vmstat for a fixed period of time, define the number of runs. Here, vmstat will report system status at 3 seconds interval, for 10 times.

$ vmstat 3 10

Check CPU utilization using Glances

Glances is a powerful tool for monitoring system status. It’s written in Python that uses the psutil library for grabbing various system information. Glances offer lots of in-depth system info like CPU monitoring, memory, network usage, disk I/O, processes, and filesystem utilization, etc. Check out Glances at GitHub.

Installing Glances is a simple task. The following method will work on any GNU/Linux distro. All you need is to have either curl or wget installed in your system. Glances will be installed with all the necessary dependencies.

$ curl -L https://bit.ly/glances | /bin/bash
$ wget -O- https://bit.ly/glances | /bin/bash

Glances are also available as a snap package. Assuming you have snappy (snap package manager) installed in your system, install Glances snap from Snapcraft. Check out Glances at Snapcraft.

 $ sudo snap install glances

Using Glances is very simple. To start the standalone mode, run the following command.

$ glances

Glances also offer to run in web server mode. To start the webserver, run the following command.

$ glances -w

To access the server, go to the following URL.

$ http://<IP_address>:61208

For raw information output, Glances can print the output to STDOUT.

 $ glances --stdout cpu.user,mem.used,load

Final thoughts

There are plenty of ways to get CPU utilization. While all of them work just fine, depending on your necessity, you may have to stick with a few of them. If you’re a system admin, then mastering top/htop and Glances offer the most flexibility. If you just want a quick update of the system resource consumption, then other methods offer a better experience.

Checking CPU utilization is fine and useful. However, to ensure stability, it’s necessary to verify that your system can function fine even under the maximum stress. Check out some useful Linux apps to stress test and benchmark CPU performance.

Happy computing!

]]>
How to List Open Ports on Linux? https://linuxhint.com/how_to_list_open_ports_on_linux/ Wed, 09 Dec 2020 04:58:04 +0000 https://linuxhint.com/?p=80312

In networking, a port is an interesting feature. It’s a way for network traffic to identify the destination app or service. Each process/service gets its unique port. A port will always be associated with the IP address of the host along with the protocol.

This is a favorite metaphor of mine to describe what a port is. Imagine a ship loaded with cargo, which will travel to a distant land. What information is needed to reach the destination properly? For the sake of simplicity, let’s say it needs the country (the IP address) and the port the ship will dock.

In this guide, check out how to list open ports on Linux.

Ports on Linux

Ports act as an endpoint of communication. It’s a 16-bit number (0 to 65535 in decimal). While the range is large, for ease of use, ports are categorized into three categories. Each category is labeled as the range of port value:

  • 0 to 1023: These are the “Well-known” ports, also known as the “System” ports, which are reserved for system processes that offer a wide variety of network services. To bind with a “Well-known” port, a process must have superuser privilege.
  • 1024 to 49151: These are the “Registered” ports, also known as the “User” ports, that are designated by IANA for specific services. Upon request, a process may have access to them. In the case of most systems, it doesn’t require any superuser privilege to use these ports.
  • 49152 to 65535: These are the “Dynamic” ports, also known as the “Private” ports. These ports can’t be registered with IANA. These ports are open to using for private or customized services and may also be automatically allocated as ephemeral ports (short-lived ports used by IP).

In Linux, there are multiple ways of checking the open ports. By default, any port will remain closed unless an app is using it. If a port is open, then it must be assigned to a service/process.

List Open Ports

It’s easier to identify which ports are in use rather than which ports are open. That’s why the following section will feature methods to list all the ports that are currently in use. In Linux, there are multiple tools available for the task. Most of them come built-in in any Linux distro.

Learning which ports are currently open can be useful in various scenarios. It’s possible to configure a dedicated port for a certain application. An open port may also be a strong indication of intrusion in the network.

The following methods are demonstrated on Ubuntu 20.04.1 LTS.

List protocols and open ports from /etc/services

The /etc/services file contains information about the currently running services. It’s a big file, so ready to get overwhelmed.

$ cat /etc/services | less

List open ports using netstat

The netstat tool is a utility for displaying network connections for TCP, routing tables, and various network interfaces. It also offers network protocol statistics. By using netstat, we can list all the open ports of the system.

Run the following netstat command:

$ netstat -atu

Let’s have a quick breakdown of all the flags we used in this command.

  • a: Tells netstat to show all sockets
  • t: Tells netstat to list TCP ports
  • u: Tells netstat to list UDP ports

Here’s another variation of the netstat command:

$ netstat -lntu

There are two new flags used in the command. What do they mean?

  • l: Tells netstat to print only the listening sockets
  • n: Tells netstat to show the port number

To display the PID of the process that’s using a port, use the “-p” flag:

$ netstat -lntup

List open ports using ss

The ss tool is a utility for investigating socket. Its usage is similar to netstat.

To list the open ports, run the following ss command:

$ ss -lntu

The flags are similar to netstat. The functions they describe are also quite similar.

  • l: Tells ss to display listening sockets
  • n: Tells ss not to try to resolve service names
  • t: Tells ss to display TCP sockets
  • u: Tells ss to display UDP sockets

List open ports using lsof

The lsof command is to list open files. However, it can also be used for displaying the open ports.

Run the following lsof command:

$ lsof -i

To get the open ports of a specific protocol (TCP, UDP, etc.) then define it after the “-i” flag, use:

$ lsof -i <protocol>

List open ports using nmap

The nmap tool is a powerful one for network exploration and security/port scanning. It can report all the open ports in the system.

To list the open TCP ports, run the following nmap command. Here, the IP address is of the host computer:

$ sudo nmap -sT -p- localhost

Here, there are two portions of the command argument.

  • -sT: This section tells nmap to scan for TCP ports.
  • -p- : This tells nmap to scan for all 65535 ports. If not used, then nmap will scan only 1000 ports by default.

If you need to list the open UDP ports, then run the following nmap command:

$ sudo nmap -sU -p- localhost

To get both the open TCP and UDP ports, use the following command:

$ sudo nmap -n -PN -sT -sU -p- localhost

List open ports using netcat

The netcat tool is a command line utility for reading and writing data across network connections over the TCP and UDP protocols. This tool can also be used for listing open ports. It can perform tests on a specific port or a range of ports.

The following netcat command will scan the port from 1 to 1000. The netcat command will perform the scan on TCP protocol by default:

$ nc -z -v localhost 1-1000

It can also be extended to the entire list of possible ports:

$ nc -z -v localhost 1-65535

Let’s have a quick breakdown of the flags.

  • z: Tells netcat to scan only for open ports without sending any data
  • v: Tells netcat to run in verbose mode

To get only the open ports from this list, filter the output with grep for the term “succeeded”.

$ nc -z -v localhost 0-65535 2>&1 | grep succeeded

If you want to perform the scan on UDP protocol, then add the “-u” flag.

$ nc -z -v -u localhost 0-65535 2>&1 | grep succeeded

Final Thoughts

As demonstrated, there are tons of ways to scan for open ports on Linux. I suggest trying out all the methods before you decide which one to master. If you’re using a certain tool like netcat or nmap regularly, then mastering the associated methods will be the most beneficial.

Happy computing!

]]>