in

The Easy Hacks In Linux Using Command Line Codes, Command Line Hacks

The Best Linux Hacks

Hello Friends, In this article, we are going to share some easy hacks in Linux using the command line codes. Let’s get into the article. Linux is one of the best open source operating system & it contains a huge amount of little hacks with it. By handling the Linux in a proper manner you will go the core of any process. The little hacks are:

Jump To:

How to schedule a Linux Job without using Cron:

The cron job means, doing a particular work repeatedly for the desired time variance. In simple, scheduling the job to do automatically. Here the below command will help you to run a particular command for every 10 seconds and that command will write the date in a file named as “dates.txt“. This can be achieved by using the following command.

while true; do date >> dates.txt ; sleep 10 ; done &

How to use? Copy the above code and paste in terminal

Explanation of Commands & Switches:

  • While true– It is the script to do a loop function when the condition is true. It will run to infinite as the conditions become true.
  • do– Which performs the condition follows.
  • dates.txt– In this file, the output of the above command will save.
  • >>– This operator ensures that the values in the dates.txt are not overwritten when the new value entered in that file.
  • sleep 10– It says the time interval for the above command. This code will run the command for every 10 seconds. If you want to run for every 5 minutes and you just need to do a little change in the command and that is: (5*60) 360. Here the “5” represents the minutes, “60” means seconds.
  • done–  Which ends the command
  • &– Restart the whole command otherwise its just the loop.
Check this too  Basic Linux Commands & Codes for Beginners[Ubuntu & Mint & More]

In a similar way, you will able to run any command in a repeated manner without cronjobs. With this, you will able to call a script in a particular period of time interval. The name of the script is “script.commandname.sh

It is suggested to use this with a directory address with the script to run without any error, in simple that you need to provide the entire path to run a script in a loop. The command will be:

while true; do /bin/sh script_commandname.sh ; sleep 100 ; done &

How to use? Copy the above code and paste in terminal

From the above code, you will be able to run a script in the loop process without using the cronjobs. The hacks for replacing the cron jobs are for the simple commands. The cron jobs methods are officially suggested to use your Linux more efficient.

Clear Terminal without “Clear” Command

After a long time of working with the Linux terminal, The terminal seems to be very clumsy. It is filled with commands, codes and etc. To clear all those commands and results without using the “Clear” command, you need to follow the below steps

  • By clicking “ctrl+I” will clear the terminal with hassle-free.

Note: The above trick is keyboard combination and so it may not work inside the terminal and so we suggest you to use the “clear” command in the terminal to clear the terminal.

Command to run back to the current directory automatically:

If you use any command to access a particular directory and then you need to write another command to get back to the older directory. To minimise this, there is a simple hack is readily available to getting back to the current directory automatically without entering any new command in the terminal. To do this you just run the commands inside the parenthesis “ ( command ) ” simply.

Check this too  Grep Command in Linux: Syntax, Options & Grep Examples Commands!

Example command:

[email protected]:~$ (cd /home/avi/MyDocuments/)

How to use? Copy the above code and paste in terminal

The Output is:

[email protected]:~

How to use? Copy the above code and paste in terminal

The above sample will explain the conditions that we are talking. You may get a doubt that the command didn’t actually execute!!. The answer is No. The command executed, it gets inside the directory and we didn’t provide further functions to proceed or execute and so it gets back to the original directory. In the same code, we will give some additional function as tweak this program inside the parenthesis.

[email protected]:~$ (cd /home/avi/MyDocuments/ && ls -l)

How to use? Copy the above code and paste in terminal

The output of the above command is:

-rw-r—– 1 avi avi 54272 Oct 19 18:37 file1.txt

-rw-r—– 1 avi avi 54272 Oct 19 18:37 file2.txt

[email protected]:~

How to use? Copy the above code and paste in terminal

From the above sample output, You can see that the command executed successfully and it get inside the directory and do some kinds of stuff and get back to the old directory. Now you will understand how these codes are working without any doubts.

That’s it, friends. We have reached the end of this article. We shared some little Linux hacks here, try this on your Linux server. If you have any doubts and then feel free to comment us.

  • Article Length
  • Content Explanantion
  • Content Clarity
4.7

Summary

We shared some little Linux hacks here. For more tutorials we suggest you see our homepage here: Tecrobust

Leave a Reply

Your email address will not be published. Required fields are marked *

Written by Rachel

I'm Rachel, From Arizona. Am playing the "Content Management" Role in Tec Robust. I started working in TR from Jan 2019. Big Marvel Fan.

Contact me:
tecrobust [@] gmail.com
Sub: Message to Rachel

How to Change Hostname on Linux Ubuntu Unity

Change Hostname Permanently on Ubuntu 18.04.1 LTS

Cron Jobs Linux

10+ CronJob Scheduling Task In Linux Using Terminal