The beauty of Linux is that it is made by programmers, for programmers. It can run on almost any hardware and there is an endless variety of distributions for almost every use case. It is preferred by programmers for its versatility, scalability, container portability, security, and many other features.

By Nuno Martins, senior channel solutions rchitect at Red Hat

Most importantly, it’s free and open source, which means that it is built and supported by a community of developers who are always at the forefront of innovation and are willing to help each other out.

Knowing a few useful command line tricks can save you a lot of time and frustration. Some you may already know, and others may prove to be a hidden gem you weren’t aware of before. Either way, here are some of the essential command line tips and tricks that I think could save you a couple of keystrokes.

Back to basics

Before we dive into the deep end with these command line tips, let’s assume not all of us are experts, and make sure we’ve got the basics covered. When using the Linux command line, or ‘shell’, it’s important to keep in mind that all commands, files, and directory names are case sensitive, and file extensions (such as .exe) are determined automatically by reading the file header.

Another command that some people forget, while others use it every minute, is using “cd -” to return to your previous directory. This proves particularly useful when you end up down a long directory path, move to a completely different path and realise you need to go back. It’s also good to know that if you enter only “cd”, you’ll go straight to the home directory.

Additionally, the “rm” command is widely used to delete files, but it does not delete them completely. After deletion, files can still be recovered using special software, so if you really value your personal data, you should use the shred command as follows: “shred <filename>” and “shred –help” to see the available command options.

The !!

How many times have you run a long command only to find out that it requires root privileges, but you forgot to add “sudo” at the beginning? If you enter “sudo !!”, the command line will replace the “!!” with the last command you tried to run, and you’ll never have to type it all out again. The “sudo” command stands for “super user do” and it’s one of the most important commands in a Linux administrator’s arsenal.

Run until success

When you need to run a command until it succeeds, like pinging a server until it becomes available, you don’t have to type in “!!” every time. You can simply use a “while !” (while not) loop to achieve that. There are many ways to do it, but here’s a simple example. If you want to display the contents of “filename” until it becomes available, you can do it as follows:

“$ while! cat filename

Do echo filename is not ready sleep 5 done”

The reverse search

Forgetting an exact command line after using it a few minutes or hours ago happens all the time, and finding it by scrolling through your history is less than optimal. The reverse search function is the answer. Press “Ctrl+R”, type a part of the command, and the reverse search will find the closest match in your recent history.

The “no hang up” command

Ending a terminal session will end any program you’re running on it. To prevent this and keep the program running in the background, you can use the “nohup” command. This command is also often used in combination with the “nice” command to run processes on a lower priority.

Help is only a keystroke away

Almost all Linux commands and command line tools come with a help page that tells you how to use them. Most of you probably already know this, but it can be accessed simply by adding “–help” to the end of the command. What some of you may not know is that if you’re ever feeling lonely on a late-night coding session, you can also type in “echo “You can do it!” cowsay” to spawn a Linux cow to motivate you.

The editor to rule them all

Apart from running commands in linux, one of the most critical skill set is to be able to edit configuration files and build scripts. The most important tool you will use for this is the ever-faithful text editor. Now, Linux has many choices but the one editor to rule them all is Vim. Learn it, it will make your life easier and enable you to be efficient when you are working in and around the configuration files and scripts that make up your systems.

Get a basic understanding of Security

One thing we all do when we are learning is to try and find an easier way. You can look at the most popular distributions of Linux and they tend to be the ones which are easier to get started with. One serious component people forget about is basic security. We have all been there, something doesn’t work and we change the permissions to allow all access, or we disable things like Selinux (Security Enhanced Linux).

These components are just as critical to understand than learning the CLI tools. I’m not saying you need to be a security expert, but you should learn the basics about permissions, user accounts and the best practices. This way you arent exposing yourself or your systems while you learn.

Automation is the way forward

Once you start to get comfortable with Linux and all its components, Its important to start looking at things like Ansible. Ansible is an automation tool used in almost every component or requirement of modem IT infrastructure. Official certifications like Red Hat’s Certified Engineer actually require you to be able to automate a lot of the daily tasks you would do as a Linux professional. Ansible is simple, powerful and agentless and it would definitely be a recommended skill to work on for any Linux Ninja soon to be Samurai.

Official Training

Lastly, if there is one thing that you could do that would immediately give you more knowledge and grow your skills and understanding of Linux is to find a few official courses. Now, I know many of you are saying, why get training when you can just Google? Training gives you the right way to do things, and it gives you the skills and recognition that future employers or clients will understand. Official certifications are a great way to really test yourself and prove your Linux kung fu is strong enough.

The platform of the future

I hope that some of you have found these basic tips and tricks useful. The world of Linux is a deep rabbit hole and there is always something new to learn and discover – and using the right Linux platform can make everything much easier.

Red Hat’s Enterprise Linux is the world’s leading enterprise Linux platform and provides more than just software and support. It gives programmers access to the resources, tools, and technologies they need to write or reuse reliable software. If you haven’t joined the open source movement yet, why not try it out for free?