Why keep a first aid kit or fire extinguisher in your home? Same with these commands: You'll never know when they might come in very handy.
I use the Linux command line daily, but that's because I learned Linux the hard way and those old lessons stuck. Most users could go their entire Linux lifetime and never run a single command. Some will use the very basic commands (such as ls, mkdir, and cd), while others might dive into more complicated options.
Still, there are a handful of commands that I consider to be must-know -- even though they might never get used. Why is that, you ask? Well, why keep a fire extinguisher handy in your kitchen? Or a first aid kit in your bathroom? Because you want these items ready if and when you should need them. Same with these commands: You'll never know when they might come in quite handy.
Also: The first 5 Linux commands every new user should learn
Let me share with you the five commands that I consider to be important to know, even if you never use them. Ready?
The diff command essentially compares two files, line by line, and presents the differences between the two. This command is fairly easy to use but the results can be confusing. Here's a simple example.
The key is 1c1. What that means is line 1 in the first file was changed and the change is found in line 1 of the second file. You might also see 1a1, which means there was an addition, or 1d1, which means there was a deletion.
This command has come in very handy when I need to see changes made in configuration files or just about any other type of text file (it cannot be run on binary files). Make sure to read more about diff with the command:
The tail command is used to view the last few lines of output from the last part of a file. If you were to issue the command tail zdnet1, the output would list the last few lines of whatever that file contains.
However, there's a much more important way to use tail. Say something is going awry with your computer and you want to view a log file in real-time. For example, you might want to view the real-time updates to the syslog file, which can be done using the -f option (for follow). That command would be:
I've used the tail command quite a bit over the years but it's not something I use every day. When I have used the tail command, it's helped me solve whatever problem was occurring every time.
The userdel command is exactly what it looks like, a way to delete users. If you're the only user on your system, you'll likely never use this command. However, there may come a day when you have to add a new user (such as for guest access). If that's the case, you might eventually need to delete that user and will be thankful you know how to issue the command:
Where USERNAME is the name of the user account to be deleted.
Keep in mind, if you also want to delete the user's home directory (and everything in it), you'll need to add the -r option, like this:
The whatis command is a quick way to know what a command does. Instead of having to read the man page for a command, do something like this:
The results will include a basic description of what the command does, like this:
You won't get any help on using the command but at least you'll know what the command does.
On Linux, you can add aliases, which can make the command line much easier. Say, for instance, you have a particular command you need to run regularly but you don't want to type it all out. For example, you regularly run the following two commands:
You could also run those as a single command like so:
Instead of having to type that every time, create an alias like this:
The only drawback to using the above command is that the alias will be deleted after a logout or reboot. If you want to make that permanent, add the alias to the bottom of the ~/.bash_aliases file.
Also: The 6 Linux commands you need to know for user management
And there you have it, five commands you might never need but will be glad you know. Remember, to learn more about each, open the manual page with the command man COMMAND (where COMMAND is the command in question).