• Digital Hill Facebook
  • Digital Hill Twitter
  • Digital Hill LinkedIN
  • Digital Hill Instagram

Call Us Today! 888.537.0703

Tips and Tricks for Linux Command Line

Linux is a fantastic operating system with many tools available to cut down on routine work. It provides both a command-line interface and a graphical user interface to help you get your work done faster. 

It’s not just an OS anymore; it’s a platform for everything from desktops to servers to embedded systems. As an open-source, modular system, it offers a wide range of distributions and customization options for free.

And one of its biggest advantages is the security system itself. Although not entirely secure, it poses less of a threat than Windows or MacOS, which is why cybersecurity consulting companies in Orlando swear by it. This is because some versions of Linux, like Kali Linux, come with hacking tools as part of the package.

But many people get stuck on hard tasks because they don’t know about the shortcuts on the Linux command line. 

And it’s not only beginners to Linux that have trouble getting underway; even seasoned command-line veterans occasionally stumble onto a feature that makes them wonder, “Where have you been all my life?”

This will show you some advanced Linux command techniques that will make your life easier. Using the following, you will be able to accomplish more in less time by reducing the number of times you need to use the keyboard and mouse.

Autocompletion

Working in Linux could become tedious if you had to repeatedly type the same long string of commands.

However, there are effective strategies and procedures in place to avoid such complications.

The tab key, for example, will suggest alternatives based on what you have already typed. When you press the tab key after Linux autocompletes a string, it shows a list of possible alternatives.

By using this method, tasks can be done more quickly and efficiently. Remember it because it isn’t as impressive or obvious when you’re just getting started with Linux. As a result, it may be simple to overlook or forget.

Turning Back to Home and Last Working Directory

Let’s say you find yourself in a directory with a long path and then navigate to a directory with a completely different path. You remember that you need to return to the previous directory and follow the same steps. To do so, simply input the following command: cd – .

The action will revert you to the previous directory. The long directory path is no longer required to be typed or copied and pasted.

However, if you want to return to your home directory from anywhere in the Linux command-line, you use the similar command which is cd ~ .

Figure Out the Right Command

It’s frustrating when you want to do something but can’t since you don’t know the right command. In this case, the apropos command can help you find the right command to finish your mission. 

For example, you want to copy files, but you don’t know the proper commands. To get the perfect result, you can run the following command in the terminal:

apropos “copy files”

Perform Multiple Commands at the Same Time

Assume you need to run several Linux commands sequentially. Should you wait for the first command to complete before executing the next?

You can accomplish this by using the “;” separator. This allows you to run multiple commands on a single line. There is no need to wait for the previous commands to complete their tasks.

command-1; command-2; and command-3

Performing Multiple Commands at the Same Time Only If the Previous Command Was Successful 

To save time, you can run multiple commands at once, as you saw in the previous command. What if, however, you must guarantee the success of commands at all costs?

Think about a situation where you need to build some code and then, if the build went well, run the make command.

In this situation, the && delimiter will work fine. The logical operator && ensures that a command is executed only if the one before it was successful.

command_1 && command_2

Find the Commands You Were Looking For Quickly and Use Them Again

If you ever need to reissue a lengthy command you used a few minutes or hours ago but have forgotten the precise order, there is an easy way to return to it. 

You can save yourself time with a reverse search. With a search term, you can find the command in the log.

To use reverse search, simply start typing the opposite of the command, followed by the Ctrl+R keys. It will do a command lookup and return results for any that match the query.

ctrl+r search_term

There will be only one result displayed by default. Repeatedly pressing Ctrl+R will display additional results that are relevant to your search. Simply pressing Ctrl+C will end the reverse search.

Supervising Multiple Log Files

When looking for a command to use to keep an eye on logs, the default choice is the tail command. It is widely used because it provides a dependable means of examining log files.

If you want to keep an eye on multiple log files at once, however, things could get a little unsteady.

The multitail command is extremely helpful in this situation. Text highlighting and filtering are two other features that a Linux system administrator or regular user might find useful.

Some Linux distributions do not include the multitail command by default. So, this command may fail to execute. Using the following syntax, you can easily set it up on the Linux command line.

$ multitail file01 file02

Overview of Command Outputs

The watch command allows you to keep tabs on the results of another command by having it run at regular intervals. Combining the watch command with the date command is a great example of this.

If you type the following into your Linux command line, the watch command will run the date command every 2 seconds, and the results will be shown on the terminal.

$ watch date

This is helpful if you need to repeatedly execute the date command but don’t want to type it in.

Run Programs After Killing a Session

Closing your shell after a program has run will terminate it immediately. This restricts the amount of multitasking that your system is capable of. Fortunately, there is a workaround. To accomplish this, use the “nohup” command.

It gives you the most ease of use and the best environment for managing your system and doing more than one thing at once. The nohup stands for “no hangup.” So the name of the command says it all. 

$ nohup wget site.com/digitalhill.zip

This command will make a file called nohup.out in the same directory. The file created will hold the output of the program that is running. The output of the program will be saved in a file called nohup.out in the current working directory.

Amazing one, right?

Locate Files With Specific Text

You can use the “grep” command to search for a file that contains a particular string of characters. Files containing the string “DigitalHill” are being located, for example. Here is the command you can use:

grep “DigitalHill” ~/Documents/*.txt

Read Files With less Instead of With cat

If you need to view the contents of a large file, cat is not the best choice. The cat command will show the entire file to the user.

If you just want to read a file, the less command is much better than Vi, Vim, or any other terminal-based text editor.

less path_to_file

Read Compressed Logs Without Extracting Them 

It causes a problem for the developer or administrator who is studying the logs. Because you may not have write permission to extract the logs, you may need to scp it to your local machine and then extract it to view the files.

Fortunately, z commands are available in such situations. Less, cat, grep, and other standard commands for dealing with log files are replaced with z commands.

Easily Fix Typos

You’ve probably heard of the alias command in Linux. What you can do is utilize them to correct errors.

For example, you may frequently spell “grep” as “gerp.” If you set an alias in your bashrc like this, the system will retype the command for you:

alias gerp=grep

Set the System’s Shutdown Time Automatically

Your system can be automatically shut down at a predetermined time. If, for some reason, you know that you need to turn off a system at 5 p.m., you can use this basic command:

sudo shutdown 17:00

And now, no matter what, your system will turn off at the given time!

Keyboard Shortcuts for the Linux Terminal

Finishing off strong with the best of tricks: shortcuts. Once you get used to these, your fingers will start working magic inside the terminal and save you so much time. Just keep in mind that the + means “and,” so there is no need to press it inside these shortcuts.

  • Ctrl + Alt + T launches a completely new terminal window.
  • Ctrl + A  moves the cursor to the beginning of the line.
  • Ctrl + E moves the cursor to the end of the line. 
  • Ctrl + C  halts the currently running command.
  • Ctrl + L clears the terminal screen.
  • Ctrl + D closes the terminal window. 
  • Alt + B moves the cursor backward for a word.
  • Alt + F moves the cursor forward for a word. 
  • Ctrl + U  removes the entire command (line). 
  • Ctrl+T changes the current character to the previous one.
  • Alt + T replaces the current word with the previous one. 
  • Ctrl + Shift + C copies the line into the terminal. 
  • Ctrl + Shift + V pastes the line into the terminal. 

Final Words

One of the most popular misconceptions regarding Linux is that it is difficult to use. This, however, is not the case. Once you get used to it, Linux is just as easy to use as any other operating system, especially when you find ways to utilize the command line for your own needs. 

So, remember to Ctrl+Shift+C all of this new information and Ctrl+Shift+V them the next time you’re inside the terminal!

Written by: