Adding a directory to $PATH on Linux

How to add directory path to $PATH variable in Linux

When you type a command into a Linux terminal, what’s really happening is that a program is being executed. Normally, to execute a custom program or script, we need to use its full path, such as /path/to/script.sh or just ./script.sh if we’re already in its residing directory. Alternatively, we can execute a lot of commands without specifying paths, like uptime or date, etc.

The reason we don’t need to specify paths for some commands is because of the $PATH variable. This is a variable that can be configured to tell our Linux system where to look for certain programs. That way, when typing date into the terminal, Linux checks the $PATH variable to see a list of directories to look for the program.

In this guide, we’ll see how to add a directory to the $PATH variable on Linux. This will enable you to call on your program or script from anywhere in the system, without needing to specify the path to where you’ve stored it. Follow along with us as we show how to view the directories in $PATH, and add a directory either temporarily or permanently to the variable.

In this tutorial you will learn:

  • How to see currently configured directories in $PATH shell variable
  • How to temporarily add directory to $PATH
  • How to permanently add directory to $PATH
Adding a directory to $PATH on Linux

Adding a directory to $PATH on Linux

Read more

Listing installed packages with apt package manager

How to list installed packages with apt command on Linux

One of the most attractive features of running a Linux system is the instant access to thousands of packages that are able to be installed from the Linux distro’s package manager.

The apt package manager does a lot more than just install packages. One example is using apt to search for packages to install. In this guide, we’ll see how to list installed packages with apt. This will only work in Linux distros that use the apt package manager, such as Debian, Ubuntu, and Linux Mint just to name a few.

In this tutorial you will learn:

  • How to list installed packages with apt package manager

Read more

Using apt search to find relevant packages

How to use apt search Linux command

One of the most attractive features of running a Linux system is the instant access to thousands of packages that are able to be installed from the Linux distro’s package manager.

Installing packages is really easy. That is, as long as you know the name of what you’re trying to install. If you don’t, then you can always search for installable packages. On distros that use the apt package manager, like Debian, Ubuntu, and Linux Mint just to name a few, this is done with the apt search command.

In this guide, we’ll show you how to use the apt search command with multiple examples. You’ll quickly learn to master the task of finding packages to install.

In this tutorial you will learn:

  • How to search for packages with apt

Read more

Appending text to a file in Bash on Linux

How to append to file on bash shell command line

The Bash shell is the most popular shell on Linux systems, and to use the shell efficiently, you need a little knowledge about Bash shell redirections. This is also an essential step in learning Bash scripting.

In this guide, we’ll show how to append text or command output to a file on the Bash shell command line. This will include several examples so you can pick the right method in any scenario.

In this tutorial you will learn:

  • How to append text or command output to a file
  • How to append and view command output at the same time
  • How to append multiple lines of text to a file
Appending text to a file in Bash on Linux

Appending text to a file in Bash on Linux

Read more

lsof command on Linux

Guide to lsof Linux command with examples

The lsof Linux command is used to list open files. On Linux systems, everything is considered a file. This means that files, directories, sockets, pipes, devices, etc are all files, therefore the lsof command will list all of these things if any of them are in use.

Along with showing you what files are in use, it will give you detailed information about which user and process is using the file. As you can imagine, this can be pretty handy in a multitude of scenarios, such as when trying to figure out what connections are being made to your system or what processes are tying up a disk that you’re trying to unmount, etc.

In this guide, we’ll show you some of the most helpful examples of the lsof command to help you get the most out of it on your own system.

In this tutorial you will learn:

  • How to use the lsof command with examples

Read more

Various examples of truncating a file on Linux

How to truncate file on Linux

Truncating files on a Linux system is a rather basic and common task for users and administrators alike. Perhaps the most common use for truncating (or emptying) a file would be in the case of log files. Clearing a bunch of old data from log files to make way for newer and up to date information can make troubleshooting much easier.

In this tutorial, we’ll show several ways to truncate a file on the Linux command line, including multiple files at once. Use the methods below on your own system, applying the example you feel will best fit your scenario.

NOTE
You can only truncate files if you have the proper Linux file permissions. Specifically, you must have write permissions on whichever files you’re trying to truncate.

In this tutorial you will learn:

  • How to use the truncate command
  • How to empty a file with Bash shell operator >

Read more

Disabling SELinux on CentOS 8

How to disable SELinux on CentOS 8

SELinux, which stands for Security Enhanced Linux, is an extra layer of security control built into Red Hat Enterprise Linux and its derivative Linux distributions, such as CentOS. SELinux is enabled by default on CentOS 8, and would have to be manually disabled if a user doesn’t wish to use it.

Although SELinux can protect our system through access control for programs and system services, it’s not always necessary to have it enabled. Some users may even find that it interferes with certain programs they try to install. In this guide, we’ll go over the step by step instructions to disable SELinux on CentOS 8, both temporarily or persistently across reboots.

In this tutorial you will learn:

  • How to check the status of SELinux
  • How to put SELinux in permissive mode
  • How to disable SELinux

Read more

Extracting tar file on Linux

How to extract tar file on Linux

The tar file type is used to combine multiple files into a single archive. Tar actually means “tape archive,” because tar’s original purpose was to be used on tape backups – that should tell you how old this format is. Linux systems still use the tar format, and it continues to enjoy widespread use to this day.

Tar files, with the extension .tar, are often called “tarballs.” These files will preserve the Linux file permissions and can combine any number of files into the single archive, but they don’t apply any compression or space savings. However, compression can be easily applied to the tar file, resulting in extensions like .tar.gz in the case of gzip compression, or .tar.xz for xz compression.

In this guide, we’ll show how to open tar files on command line and via GUI. This will include tar files with various compression applied to the archive. Check out the examples below to find out how.

In this tutorial you will learn:

  • How to open tar file via GUI
  • How to open tar file via command line

Read more

Using dpkg command on Linux

Beginners guide to dpkg Linux command

Debian Linux and other Debian based Linux distributions, such as Ubuntu and Linux Mint, use dpkg as a package manager.

You might be thinking, “I thought those distributions used apt – that’s what I always use to install packages.” That’s true, apt is also a package manager, but really it’s just passing off tasks to dpkg in the background. apt and other package managers on Debian usually just utilize dpkg to install packages or perform similar tasks.

Package manager commands like those from apt or apt-get are meant for end-users. They’re easy to use and are very familiar to most Linux users. dpkg is low-level tool that is more geared towards use by the system, but we can still use it with the dpkg command.

In this guide, we’ll go over various dpkg command examples to help you learn to use the tool and manage packages on your Debian or Debian based system.

In this tutorial you will learn:

  • How to install .deb packages with dpkg
  • How to use dpkg command through examples

Read more

Using mdadm to create a software RAID 1 array on Linux

Linux Software Raid 1 Setup

RAID 1 is a hard disk configuration where the contents from one hard disk are mirrored onto another. This provides the user with some redundancy in case a disk fails. On your Linux system, the two hard drives are represented as a single file system. But in the background, making changes to your files is actually writing the changes to two disks at the same time. You can also add more than two disks to the configuration, as long as you keep the number even. Otherwise, something like RAID 5 will be more suitable.

There are many ways to configure a RAID setup. One of the easiest and most accessible ways is through the mdadm software package, which can be installed and used on any major Linux distribution. This is easier than some other RAID setups, since it doesn’t require any special hardware (like a RAID controller) and isn’t that hard to configure.

In this guide, we’ll go through the step by step instructions to install and setup mdadm on Linux, and create a RAID 1 configuration for two hard disks. Our example scenario will consist of two empty hard disks that are each 10 GB in size. This is in addition to our main hard disk, which is just used for the operating system.

WARNING
Strictly speaking, RAID 1 is not a proper backup solution. It does provide some protection from disk failure, but what if you accidentally delete a file or a virus corrupts multiple files? Those undesirable changes are instantly written to both disks. RAID 1 provides high availability, but you shouldn’t use it as your only backup solution.

In this tutorial you will learn:

  • How to install mdadm on major Linux distros
  • How to partition hard disks for RAID setup
  • How to create a new RAID device in mdadm and mount it
  • How to keep the RAID array mount persistent
Using mdadm to create a software RAID 1 array on Linux

Using mdadm to create a software RAID 1 array on Linux

Read more

Various xargs command examples on Linux

Examples on how to use xargs command on Linux

The xargs Linux command allows a user to execute command lines from standard input. If that sounds confusing, it might be easier to look at a basic example. The following command would use xargs to cat all the files listed by the ls command.

$ ls
1.txt  2.txt  3.txt

$ ls | xargs cat
this is file1
this is file2
this is file3

In the command above, we piped the output of the ls command to xargs, and used the cat command to list the contents in each of the three files. Most uses of xargs involve piping to it from a different command, and utilizing it to execute another command in succession. If you want to start off with additional basic examples, check our guides on xargs for beginners or multi-threaded xargs examples.

Read more

How To Upgrade Ubuntu To 21.04

How To Upgrade Ubuntu To 21.04

The new Ubuntu 21.04 is expected to be released on 22 April 2020. However, there is no need to wait until then. If you feel adventurous and impatient you can upgrade to Ubuntu 21.04 today. All you need is to have fully upgraded and updated Ubuntu 21.10 Groovy Gorilla at your disposal.

In this How To Upgrade Ubuntu To 21.04 Hirsute Hippo tutorial you will learn:

  • How to fully update and upgrade your current Ubuntu system.
  • How to configure the release upgrader.
  • How to upgrade your Ubuntu system.

Read more