How to run cron job every minute on Linux/Unix

I want to run a cron job that should run a specific shell script /home/jobs/ every minute. How do I use crontab to execute script every minute on Linux or Unix-like system? How can I run cron job every minute on Ubuntu Linux?

The cron daemon used to execute command or scheduled commands or scripts under Linux or Unix-like system.
Running crontab to execute script/command every minute
Cron is one of the most useful tool in a Linux or UNIX like operating systems. It is usually used for sysadmin jobs such as backups or cleaning /tmp/ directories and more. Let us see how can we run cron job every one minute on Linux, *BSD and Unix-like systems.

macOS users: First, install Homebrew on macOS and then type the following brew command:
brew tap discoteq/discoteq
brew install flock

Run cron job every minute

The syntax is:
* * * * * /path/to/your/script
To run a script called /home/vivek/bin/foo, type the crontab command:
$ crontab -e
Append the following job:
* * * * * /home/vivek/bin/foo
Save and close the file.

How does it work?

The syntax for crontab is as follows:

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

The asterisk (*) operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month. An asterisk in the every field means run given command/script every minute.

A note about using /etc/cron.d/ directory

If you put cronjob in /etc/cron.d/ directory you must provide the username to run the task as in the task definition:
* * * * * USERNAME /path/to/your/script
For example, run a script that uses rsync to replicate changed files. Create a file named /etc/crond.d/rsync.job
$ sudo vi /etc/crond.d/rsync.job
Append the following:


# Start job every 1 minute
* * * * * root /root/bin/

# Another example to set up cron job every 1 minute is a commonly used in cron schedule.
* * * * * root /usr/bin/perl /usr/lib/cgi-bin/check.for.errors.cgi

Save and close the file. Here is a sample /root/bin/ file:

# Usage: A sample shell script to replicate newly added 
# HTML files/images/js etc on all $servers i.e. poor mans
# file replication service ;)
# Author: Vivek Gite, under GPL v2.0+
# Note: Set ssh pub key based auth to work this script
# ------------------------------------------------------------
_rsync_opt='-az -H --delete --numeric-ids --exclude=cache/css --exclude=tmp/js'
# user name for ssh
# server nodes 
servers="node01 node02"
# Source and dest 
# Let us loop it and do it
for b in ${servers}
 ${_rsync} ${_rsync_opt} "$@" ${S} ${u}@${b}:${D}

A note about dealing with race condition when running cron job every minute

We are going to use the flock command which manages flock(2) locks from within shell scripts or from the command line. Modify your script as follows to ensure only one instance of a Bash script is running every minute:

## Copyright (C) 2009 Przemyslaw Pawelczyk <>
## This script is licensed under the terms of the MIT license.
## Source
# Lockable script boilerplate
### HEADER ###
LOCKFILE="/var/lock/`basename $0`"
_lock()             { flock -$1 $LOCKFD; }
_no_more_locking()  { _lock u; _lock xn && rm -f $LOCKFILE; }
_prepare_locking()  { eval "exec $LOCKFD>\"$LOCKFILE\""; trap _no_more_locking EXIT; }
exlock_now()        { _lock xn; }  # obtain an exclusive lock immediately or fail
exlock()            { _lock x; }   # obtain an exclusive lock
shlock()            { _lock s; }   # obtain a shared lock
unlock()            { _lock u; }   # drop a lock
# Simplest example is avoiding running multiple instances of script.
exlock_now || exit 1
_rsync_opt='-az -H --delete --numeric-ids --exclude=cache/css --exclude=tmp/js'
# user name for ssh
# server nodes 
servers="node01 node02"
# Source and dest 
# Let us loop it and do it
for b in ${servers}
 ${_rsync} ${_rsync_opt} "$@" ${S} ${u}@${b}:${D}
# Remember! Lock file is removed when one of the scripts exits and it is
#           the only script holding the lock or lock is not acquired at all.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • Httqm Jun 19, 2017 @ 7:23

    Nice article (as usual ;-)

    CRON is a very powerful + useful daemon, and it’s indeed available to fire tasks every minute. But users would start scripts every second if they could. The “run every minute” tasks are, IMHO, signs of a poor design (or CRON is not the right tool for the job, which is possible too).

  • Ben Mo Jun 20, 2017 @ 4:09

    Mac users need to do:

    brew tap discoteq/discoteq
    brew install flock

    first. Also, delete the -x flag, which isn’t currently supported by discoteq’s version of flock. I tried running the same rsync script twice simultaneously and the second instance errored out immediately. So the script works as expected. Thanks Vivek!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum