20 Linux Command Tips and Tricks That Will Save You A Lot of Time

Linux Command Tips and Tricks ,Brief: Here are a few tiny however beneficial Linux instructions, terminal tricks and shortcuts so that it will prevent a variety of time at the same time as working with Linux command line.

Have you ever encountered a second whilst you see your colleague the use of some easy Linux instructions for obligations that took you numerous keystrokes? And while you saw that you have been like, “Wow! I didn’t realize it is able to have been performed that without difficulty”.

In this article, I’ll show you some seasoned Linux command tricks on the way to prevent lots of time and in some cases, from lots of frustration. Not only your pals or colleagues will ‘wow’ at you, it’s going to also help you increase your productivity as you’ll need fewer Keystrokes and even fewer mouse clicks.

It’s now not that those are Linux recommendations for novices most effective. Chances are that even skilled Linux customers will find a few hidden gems that they have been now not conscious despite the use of Linux for these kinds of years.

In any case, you research Linux by using revel in, be it your personal or someone else’s :

Linux Command Tips and Tricks ,Cool Linux terminal tricks to save time and increase productivity

You may already understand some of those Linux command hints or possibly all of it. In either case, you’re welcome to share your favorite hints within the remark phase.

Some of those pointers also depend upon how the shell is configured. Let’s start!

Linux Command Tips and Tricks ,0. Using tab for autocompletion

I’ll start with something simply obvious and but truly important: tab final touch.

When you are beginning to kind some thing in Linux terminal, you could hit the tab key and it will advise all of the viable alternatives that begin with string you have typed to this point.

For example, if you are trying to duplicate a document named my_best_file_1.Txt, you may just type ‘cp m’ and hit tab to look the possible options.

You can use tab in completing commands as nicely.

Linux Command Tips and Tricks ,1. Switch back to the last working directory

Suppose you come to be in a protracted listing direction and then you circulate to any other listing in a very extraordinary direction. And then you definitely realize that you have to pass again to the previous listing you were in. In this case, all you want to do is to kind this command:

This will put you back in the last working directory. You don’t need to type the long directory path or copy paste it anymore.

Linux Command Tips and Tricks ,2. Go back to home directory

This is way too apparent. You can use the command under to transport to your house directory from everywhere in Linux command-line:

cd ~

However, you may additionally use simply cd to head lower back to home directory:

cd

Most cutting-edge Linux distributions have the shell pre-configured for this command. Saves you at least keystrokes right here.

Linux Command Tips and Tricks , 3. List the contents of a directory

You must be guessing what’s the trick inside the command for listing the contents of a listing. Everyone is aware of to use the ls -l for this cause.

And that’s the issue. Most people use ls -l to list the contents of the listing, whereas the same can be achieved with the subsequent command:

Again, this relies upon at the Linux distributions and shell configuration, but possibilities are which you’ll be able to use it in most Linux distributions.

Linux Command Tips and Tricks ,4. Running multiple commands in one single command

Again, this relies upon at the Linux distributions and shell configuration, but possibilities are which you’ll be able to use it in most Linux distributions.

Linux Command Tips and Tricks ,5. Running multiple commands in one single command only if the previous command was successful

In the previous command, you saw how to run several instructions in one single command to keep time. But what if you have to make sure that commands don’t fail?

Imagine a state of affairs wherein you need to build a code after which if the build became successful, run the make?

You can use && separator for this case. && makes sure that the subsequent command will simplest run when the preceding command changed into a hit.

A good example of this command is when you use sudo apt update && sudo apt upgrade to upgrade your system.

6. Easily search and use the commands that you had used in the past

Imagine a scenario in which you used a long command short time/hours in the past and you have to use it once more. Problem is which you can not bear in mind the exact command anymore.

Reverse seek is your savior right here. You can search for the command within the records the usage of a seek term.

Just use the keys ctrl+r to provoke reverse seek and kind a few part of the command. It will appearance up into the history and could display you the instructions that suits the hunt term.

By default, it will show just one result. To see more results matching your search term, you will have to use ctrl+r again and again. To quit reverse search, just use Ctrl+C.

Note that during a few Bash shells, you could also use Page Up and Down key together with your seek term and it will autocomplete the command.

7. Unfreeze your Linux terminal from accidental Ctrl+S

You in all likelihood are recurring of using Ctrl+S for saving. But if you use that in Linux terminal, you’ll have a frozen terminal.

Don’t worry, you don’t ought to near the terminal, now not anymore. Just use Ctrl+Q and you can use the terminal again.

8. Move to beginning or end of line

Suppose you are typing a protracted command and midway you realise that you needed to alternate some thing at the beginning. You would use several left arrow keystrokes to transport to the start of the line. And further for going to the cease of the line.

You can use Home and End keys here of direction however alternatively, you could use Ctrl+A to visit the start of the line and Ctrl+E to go to the cease.

I find it more convenient than using the home and end keys, especially on my laptop.

9. Reading a log file in real time

In situations where you need to investigate the logs while the software is running, you can use the tail command with -f option.

tail -f path_to_Log

You can also use the regular grep options to display only those lines that are meaningful to you:

tail -f path_to_log | grep search_term

You can also use the option F here. This will keep the tail running even if the log file is deleted. So if the log file is created again, the tail will continue logging.

10. Reading compressed logs without extracting

Server logs are usually gzip compressed to save disk area. It creates trouble for the developer or sysadmin analyzing the logs. You may have to scp it on your local after which extract it to get right of entry to the files due to the fact, at times, you don’t have to write permission to extract the logs.

Thankfully, z instructions save you in such situations. Z instructions offer alternatives of the normal instructions which you use to cope with log files which include less, cat, grep and so forth.

So you get zless, zcat, zgrep and many others and also you don’t even ought to explicitly extract the compressed documents. Please seek advice from my earlier article about using z instructions to actual compressed logs in detail.

This become one of the secrets reveals that gained me an espresso from my colleague

11. Use less to read files

To see the contents of a record, the cat isn’t always the excellent option in particular if it’s miles a large file. Cat command will display the complete document on your screen.

You can use Vi, Vim or other terminals primarily based text editors however if you just need to read a record, less command is a much higher desire.

less path_to_file

12. Reuse the last item from the previous command with !$

Using the argument of the preceding command comes accessible in lots of situations.

Say you need to create a directory and then go into the newly created listing. There you can use the !$ alternatives

A better manner to do the same is to apply alt+. You can use it. More than a few instances to shuffle between the options of the closing instructions.

13. Reuse the previous command in the present command with !!

You can name the entire previous command with !!. This comes particularly useful if you have to run a command and recognize that it wishes root privileges.

A short sudo !! Saves plenty of keystrokes right here.

14. Using alias to fix typos

You probably already realize what is an alias command in Linux. What you can do is, to use them to restoration typos.

For instance, you would possibly regularly mistype grep as a grep. If you placed an alias in your bashrc in this style:

alias gerp=grep

15. Copy Paste in Linux terminal

This one is barely ambiguous as it relies upon on Linux distributions and terminal packages. But in trendy, you should be able to copy paste commands with these shortcuts:

This one is barely ambiguous because it depends on Linux distributions and terminal applications. But in well-known, you must be capable of replica paste instructions with those shortcuts:

*Select the text for copying and right click on for paste (works in Putty and other Windows SSH clients) Select the text for copying and center click on (scroll button at the mouse) for paste Ctrl+Shift+C for replica and Ctrl+Shift+V for paste

16. Kill a running command/process

This one is possibly manner too obvious. If there is a command jogging within the foreground and you want to exit it, you may press Ctrl+C to stop that walking command.

17. Using yes command for commands or scripts that need an interactive response

If there are some commands or scripts that need user interaction and you know that you have to enter Y each time it requires input, you can use Yes command.

yes | command_or_script

18. Empty a file without deleting it

If you just want to empty the contents of a text file without deleting the file itself, you can use a command similar to this:

> filename

19. Find if there are files containing a particular text

There are multiple methods to search and discover in the Linux command line. But inside the case whilst you simply want to see if there are documents that include specific textual content, you could use this command:

grep -Pri Search_Term path_to_directory

20. Using help with any command

I’ll finish this newsletter with one greater obvious and yet very vital ‘trick’, using assist with a command or a command line tool.

Almost all command and command line device come with a assist web page that suggests a way to use the command. Often the use of help will tell you the basic usage of the tool/command.

Just use it on this style:

command_tool --help

Your favorite Linux command line tricks?

I have intentionally now not covered instructions like fuck because those aren’t widespread instructions which you’ll locate everywhere. The tricks discussed here ought to be used nearly in all Linux distributions and shells without the need of installing a new tool.

I understand that there are extra Linux command hints to save time within the terminal. Why not percentage some of your stories with Linux and do percentage your great trick with relaxation of the community here? The comment section under is at your disposal.