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:
- Schedule a Linux Job without using Cron
- Clear Terminal without “Clear” Command
- Command to run back to the current directory automatically
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.
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.
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:
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.
The Output is:
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.
The output of the above command is:
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.
We shared some little Linux hacks here. For more tutorials we suggest you see our homepage here: Tecrobust