in

The 8 Linux commands I use the most – and what they can do for you

Thanasis/Moment via Getty Images

Follow ZDNET: Add us as a preferred source<!–> on Google.


ZDNET’s key takeaways

  • The command line isn’t required when using Linux.
  • To truly maximize your Linux experience, you should still learn it.
  • Some commands are more useful than others.

Before we begin, I want to be clear: Using the command line is not a requirement for using Linux. I mention this because the idea of typing commands tends to scare off new users, and my goal – for years – has been to introduce people to the open-source operating system.

After using Linux for over two decades, I’m totally comfortable with the command line and tend to default to it for certain things. I do this because I find the command line to be more efficient than using a GUI. I can leave a terminal window open at all times and perform tasks without needing to take my hands off the keyboard.

Also: The first 8 Linux commands every new user should learn

So, yes, there are certain Linux commands that I can count on to use every single day. Those commands help me do the things I do, keep my systems running smoothly, and ensure that I’m informed about what’s happening on my machines.

Of course, everyone’s computing experience is different, so what you need will likely differ from the commands I depend on. That said, here are the eight Linux commands that are almost guaranteed to be run daily from my keyboard.

1. top

I always like to know what’s going on under the hood, especially if I feel as if something has gone awry. When that time comes, top is my command of choice. With top, I can quickly find out how many system resources an app or command is using. On top of that, I can see the PID (Process ID) associated with that command or app and can use it to kill the app, should it be necessary. 

The reason I use top rather than one of the GUI apps is that I can remote into a machine and uncover the information from the terminal. Top is fast, easy to use, and never fails me.

–>

To open top, issue the following command:

top

2. ssh

I could make a case for ssh being the most important command on the list. Why? Consider this: Sometimes VirtualBox loses its mind, and a guest VM will start behaving badly enough to lock up my system. When that happens, I can use ssh to access the system, use top to find out the PID associated with the VM, then kill the VM with the kill PID (where PID is the process ID of the VirtualBox guest) — and I’m all set.

Also: My top 5 password managers for Linux – and my favorite works on Windows and MacOS too

I often have to remote into other machines on my network (or outside of my network) to get certain things done (like updating a server). I also use scp (which is part of ssh) to move files around on my network, so, yeah, ssh is pretty important.

SSH is simple to use. For example, if I want to remote into a server on my LAN, I could issue the following:

ssh jack@192.168.1.100

3. sudo

This one is probably the command I run most often — because I’m always installing software, updating apps, managing processes and services, and doing all sorts of things that require admin privileges. If it weren’t for sudo, I’d have to first change to the root user, which can be a security issue. With sudo, I gain temporary admin privileges, can run a command or app, and then know those privileges will be automatically revoked after a set period. Sudo was a very smart addition to Linux and continues to be one of the most important commands I’ve run to date.

Also: 5 obscure Linux distros you’ve probably never heard of – but should definitely try

Sudo is simple to use. You simply add it to the beginning of any command you would run that requires admin privileges like so:

sudo apt install upgrade -y

4. apt

Given how often I test and review open-source software on Debian/Ubuntu-based distributions, it should come as no surprise that apt is one of my most frequently used commands. The apt package manager simplifies the process of managing applications and even fixing broken installations (sudo apt install -f has saved my hide on several occasions). Although the GUI frontends for apt are outstanding, there are some things they cannot do (such as apt purge apt autoremove), which is why I often prefer to manage packages from the command line.

Apt is easy. For example, if you want to install GIMP, you’d issue the following command:

sudo apt install gimp -y

5. wget

Wget is one of those commands that may not get used every day, but when it does get used, I realize how important it is. When there’s a file or script I need to download, and there’s no web browser-accessible link to use, wget can get the job done. I use wget regularly, especially when installing server-based software, where the operating system probably doesn’t have a GUI to depend on. With wget, it doesn’t matter if there’s a desktop environment or not; I can still grab whatever I need to get the job done.

Also: Ready to ditch Windows? I found a powerful mini PC that’s optimized for Linux

Let’s say you want to download the source for the latest release of GIMP. You can do that with:

wget https://download.gimp.org/gimp/v2.10/gimp-2.10.0-RC1.tar.bz2

6. ps

The ps command is essential if you want to be able to manage running processes and apps. One of the main reasons why I use the ps command is to track down information about a process. For instance, I might need to know information about the running Zen Browser, and the top command doesn’t give me everything that I need. To locate the time an app has been running, process IDs, and more, you can use the ps command and pipe the output to the grep command (another important command) to see only the information related to Zen Browser. 

By using this command, you don’t have to use top and then try to snag the process ID as it bounces around in the listing as other services and apps are tracked.

Also: 5 reasons why Zen is my new favorite browser (RIP, Opera)

To use the ps command with grep to find information about Zen Browser, you could issue the command:

ps aux | grep zen

Comb through the output and you should find the information you’re looking for.

7. tail

I frequently review log files to identify and resolve issues with applications or services. Log files contain crucial information that can help you understand what’s going on with your system. However, just using the less command simply shows the contents of the entire file. If a log file is lengthy and complicated, it may not be helpful. Additionally, you may want to view entries in a log file as they are written. This is particularly helpful when troubleshooting an issue and you need to view log entries as they occur in real-time.

The command for this is ‘tail’, and it will greatly simplify your log viewing. 

Also: My top 5 screen-recording apps for Linux – and they’re all free

To use tail in the way I describe above, you run it in conjunction with the -f flag (for follow). Let’s say you want to follow the /var/log/syslog file and watch, in real-time, as entries are written. To do this, you’d run the command:

tail -f /var/log/syslog

By default, tail will display the last 10 lines written to the log file. If you need fewer, you could use the -n option like so:

tail -f -n 1 /var/log/syslog

The above command would only list the last entry written to the log file. This is a great way to keep the confusion of large log entries at bay.

8. systemctl

Systemctl allows me to control processes. Not only can I start and stop them, but I can also check to see if they are running or not. If a process has died, systemctl will report it. Then I can also use it to help troubleshoot why the process stopped in the first place (with journalctl – which is part of systemctl), set the default target (such as GUI or terminal), mask or unmask a service, enable a service to start at boot, list unit files, and more. 

Also: My 5 favorite Linux text editors (and why you should be using one)

Systemctl is a must-use to keep a system running well. Those new to Linux probably won’t need to bother with systemctl at first, but eventually, you’ll want to delve into the details of this command because it proves very handy.

The systemctl command is simple. Say you want to start the SSH daemon. This can be done with:

sudo systemctl start ssh

You can also check the status of a service like so:

systemctl status ssh

If you want to stop a service, the command will look like this:

sudo systemctl stop ssh

As well, you can restart a service with the command:

sudo systemctl restart ssh

Finally, you might install a new application that uses a service, but the installation doesn’t enable the service. When you enable the service, it means the service will always start during the OS boot process. To enable a service, issue the command:

sudo systemctl enable ssh

To disable a service (preventing it from starting at boot), the command would be:

sudo systemctl disable ssh

You can also start and enable a service at the same time, like so:

sudo systemctl enable –now ssh

Get the morning’s top stories in your inbox each day with our Tech Update newsletter.

–>


Source: Robotics - zdnet.com