Linux Mint – Advanced Administration Techniques

How to Create MySQL Users Accounts and Grant Privileges

At this point, you should have a deep understanding of Linux Mint, be able to install and configure it, as well as perform common tasks such as browsing the Web, creating/editing documents, listening to music, watching videos, backing up important files, installing and removing software, executing shell commands via Mint’s terminal, and much more. By now, you’ve probably installed Mint on several of your own machines and may have even showed it off to your friends. In this chapter as well as the next, we’re going to round out your knowledge and take your skills to the next level. First, in this chapter, we’ll go over all the advanced stuff that isn’t required for your day-to-day usage but will help make you a Linux warrior. In Chapter 12, Troubleshooting Linux Mint, we’ll go over what to do when things go wrong, and help you recover from disasters.

In this chapter, we will discuss the following topics:

  • Creating command aliases
  • Making aliases persistent
  • Killing processes
  • Setting up cron jobs
  • Preparing to move to a new release
  • Exporting and importing package lists
  • Using Variables and Conditional statements in Bash
  • Monitoring resource usage
  • Monitoring CPU temperatures
  • Sending system reports via e-mail

Creating command aliases

As you may have noticed, some of the strings of command lines in the Linux shell can be long, and after a while, become a pain to type. While using the shell, you can press the up and down arrows to recall previous commands and even paste commands that you may have saved in a cheat-sheet document. These features certainly help, but there are also features that appeal to the more lazy users out there. Aliases are one of those things that when you start using them, you’ll wonder how you ever lived without them.

To illustrate the value of command aliases, consider the following command:


sudo apt-get update && sudo apt-get dist-upgrade

The previous command will first update your cached package sources and then install any updates that may be available for the packages installed on your system. To be fair, this command isn’t the longest one in the world; it’s just two commands strung together (using && in between them). However, it is long enough, and you could benefit from simplifying it. Wouldn’t it be great if there was a way to simply type update instead of sudo apt-get update && sudo apt-get dist-upgrade and have the same effect? There is such a simple way, and this is where command aliases come into the picture.

To alias the previous command, first execute the alias command in the following syntax:


alias update='sudo apt-get update && sudo apt-get dist-upgrade'

After executing the alias command given in the previous example, you can now simply type update, and you would instead be executing the full sudo apt-get update && sudo apt-get dist-upgrade command. In a nutshell, to create a new alias, you start out by first typing alias, then the name of the alias you wish to create, followed by an equal (=) sign, and then the aliased command in single or double quotes. It doesn’t matter what you name your alias, as long as it’s not a command that already exists on your system. For example, instead of naming your alias update, you could have named it ninja if you wanted to, and it would work just the same. In our example, we used update because it made sense. Now, to download the latest versions of installed packages as well as security updates, simply type update.

Another benefit of creating aliases is that you can essentially create your own command and make the alias do the same thing on multiple computers. Consider the fact that distributions such as Fedora, Arch, and Debian use different package managers, so the command to download the latest updates is different on each. You could create an alias named update on computers installed with various flavors of Linux to run the local update command for that computer. For example, you could alias yum update (Fedora’s update command) to update as well and have the same end result. This is especially valuable in an enterprise, where consistency always helps.

So, now that we’ve created an alias, how do we remove it? That’s easy—we can use the unalias command. The syntax of the command is simple; all you have to do is type unalias followed by the name of the alias you want to remove. Considering our example update command, you would type the following statement to get rid of it:


unalias update

With this, the update command would be wiped out. Feel free to practice the alias command and simplify your most used commands.

Comments are closed.