This cronjob command has made a lot of the things easier to do. If you are a DevOps Engineer or a computer programmer who uses Ubuntu OS regularly might be aware of a tool called cronjob. So in this ...
If you are a DevOps Engineer or a computer programmer who uses Ubuntu OS regularly might be aware of a tool called cronjob. So in this article, I’ll be giving you a one handy command which I recently managed to learn during my DevOps training.
First of all, for everyone who is a bit new to this tool let me guide you through some basics first.
Cronjob: it creates jobs that a user can run on a scheduled time on automation which makes their tasks easier to do. There is a cron “daemon” that runs on these systems.
A daemon is a program that runs in the background all the time, usually initiated by the system. This cron daemon is responsible for launching these cron jobs on schedule. Here is the basic syntax ;
10 * * * * /usr/bin/php /www/virtual/username/cron.php > /dev/null 2>&1
You can refer to crontab guru which can guide you on how to specify time and days for your job easily through their wonderful and smart gui.
Possibilities are infinite.
Now coming to the main topic, what we’re gonna do is to generate a job which will keep x amount of recent files in your specified directory and will delete the rest of them
0 2 * * 0-6 cd /home/username/dir && ls -tr | head -n -2 | xargs --no-run-if-empty rm
Okay. So the above-mentioned command will find the recent 2 files and delete the rest of the files *at 02:00 on every day-of-week from Sunday through Saturday. *(0–6 is a defined range for the days of the week )
So here is the command, if you wanna try it then create a demo directory and demo files before putting this command onto the live project.
Although we still talk about programming as a standalone career, the dominance of technology in our lives makes it clear that coding is much more than a career path. In my opinion, computer science is more than a college major or a high-paid job; it’s a skill, essential for thriving in a modern-day economy. Whether you work in healthcare, marketing, business, or other fields, you will see more coding and have to deal with a growing number of technologies throughout your entire life.
I remember my first fumble with basic on my ZX Spectrum computer back in the 1980s, ploughing through pages of basic commands and example code without any real idea of how I could write programs myself
Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code that implements a certain algorithm. Playing code golf is known as "golf scripting". Code golf challenges and tournaments may also be named with the ... Some code golf questions, such as those posed on general programming ...
This article will introduce the concepts and topics common to all programming languages, that beginners and experts must know!
Static code analysis is a method of debugging by examining source code before a program is run. It's done by analyzing a set of code against a set (or multiple sets) of coding rules. Static code analysis and static analysis are often used interchangeably, along with source code analysis.