Linux/Unix bash shell script to purge Cloudflare url/images from the command line

Here is a simple and easy to use bash shell script to purge/delete Cloudflare url/images cache from the command line without using web interface.

# Purpose: Purge a single url using cloudflare API from the bash shell 
# Author: Vivek Gite
# License: GNU GPL v2.x+
## Login to Cloudflare to get API keys ##
## Get url to purge ##
[ "$urls" == "" ] && { echo "Usage: $0 url"; exit 1; }
## Let user know ##
echo "Purging $urls..."
## Purge it using curl command ##
curl -X DELETE "${zone_id}/purge_cache" \
     -H "X-Auth-Email: ${login_id}" \
     -H "X-Auth-Key: ${api_key}" \
     -H "Content-Type: application/json" \
     --data "{\"files\":[\"${urls}\"]}"
echo ""

How do I use this shell script?

Run it as follows to purge a url named
Sample outputs:

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics via:
Category List of Unix and Linux commands
File Management cat
Firewall Alpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN Alpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

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

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.