Super Handy Linux Command Tips and Tricks That Will Save you a lot of Time and Increase Your Productivity

0
3

To save time while working with Linux command line or terminal here are some useful commands.

1. Use Tab for auto completion

  • When you are starting to type something in Linux terminal, you can hit the tab key and it will suggest all the possible options that start with string you have typed so far.

2. Switch back to last working directory

You can use the command below to move to your last used directory

cd -

3. Go back to Home directory

You can use the command below to move to your last used directory

cd ~

4. List the contents of a directory

ll
ls -alrth

5. Running multiple commands

You can use the ‘;’ separator for this purpose. This way, you can run a number of commands

 commande1; command2;  command3  

6. Run command and if only the previous one was successful

command1 && command2

7. Search easily commands used in the past

ctrl+r term_to_find 

8. Unfreeze terminal after accidental Ctrl+S

You probably are habitual 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 have to close the terminal, not anymore. Just use Ctrl+Q and you can use the terminal again.

Ctrl+Q

9. Move to beginning or to end of line

You can use Home and End keys here of course but alternatively, you can use Ctrl+A to go to the beginning of the line and Ctrl+E to go to the end.

  • Ctrl+A to move to beginning of line
  • Ctrl+E to move to end of line

10. Delete entire line from cursor position

In the Linux terminal, if you press Ctrl+U, it deletes everything from your current cursor position to the beginning of the line.

Similarly, if you press Ctrl+K, it deletes everything from your cursor position to the end of the line.

11. Read file in real time

tail -f filepath

12. Reading compressed logs without extracting

z commands save you in such situations. z commands provide alternatives of the regular commands that you use to deal with log files such as less, cat, grep etc.

So you get zless, zcat, zgrep etc and you don’t even have to explicitly extract the compressed files

13. Use less to read files

To see the contents of a file, cat is not the best option especially if it is a big file. cat command will display the entire file on your screen.

less filepath

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

Using the argument of the previous command comes handy in many situations:

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

You can call the entire previous command with !!. This comes particularly useful when you have to run a command and realize that it needs root privileges.

16. Using alias to fix typos

For example, you might often mistype grep as gerp. If you put an alias in your bashrc in this fashion:

alias gerp=grep

17. Copy Paste in Linux terminal

shortcuts:

  • Select the text for copying and right click for paste (works in Putty and other Windows SSH clients)
  • Select the text for copying and middle click (scroll button on the mouse) for paste
  • Ctrl+Shift+C for copy and Ctrl+Shift+V for paste

18. Kill a running command/process

if you know the PID of process you can use :

kill -9 PID_NUMBER

19. Empty a file without deleting it

> filenametoempty

20. Find if there are files containing a particular text

grep -Pri term_to_find

May be you want to do more with Linux 😀 you can read more about certifications here Best Linux Certifications for 2022

Click to rate this post!
[Total: 1 Average: 5]

LEAVE A REPLY

Please enter your comment!
Please enter your name here