5 Linux commands you need to have ready - just in case

1 week ago 20
BOOK THIS SPACE FOR AD
ARTICLE AD
penguinjump5screenshot-2024-11-11-145623
Paul Souders/Getty Images

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? 

1. diff

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. 

Create two different files, zdnet1 and zdnet2. In the zdnet1 file, add the line This is my first ZDNET file. In the second file, add the line This is my second ZDNET file. Now, use the diff command like so:

The results will look something like this:

1c1 < This is my first ZDNET file. --- > This is my second ZDNET file.

What does it mean?

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:

2. tail

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.

3. userdel

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:

4. whatis

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:

userdel (8) - delete a user account and related files

You won't get any help on using the command but at least you'll know what the command does.

5. alias

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:

sudo apt-get update sudo apt-get upgrade -y

You could also run those as a single command like so:

sudo apt-get update && sudo apt-get upgrade -y

Instead of having to type that every time, create an alias like this:

alias update="sudo apt-get update && sudo apt-get upgrade -y"

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). 

Read Entire Article