Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

Purging a huge amount of files from public storage.

1
by mjauvin, last modified on July 21st, 2023

If you need to purge a huge amount of files from the storage/app/uploads/public folder, the framework can be used but the process can be really slow (ask Luke Towers).

In such cases, you can generate the full path and purge the files using the technique below:

  1. build your file list using tinker or an SQL query (you just need the disk_name column)
  2. dump that list in a file called fileList.txt
  3. create the script below

bulk_purge.sh

#!/bin/bash

# app root to reach the sorage, uses current directory by default
appRoot=$(pwd)

# relative path to the public uploads
publicPath="storage/app/uploads/public"

while read file; do
    echo "${appRoot}/${publicPath}/${file:0:3}/${file:3:3}/${file:6:3}/$file"
done

find ${appRoot}/${publicPath} -type d -empty | sort -nr | xargs -n1 rmdir 
  1. run the following command in your terminal:
cat fileList.txt | bash bulk_purge.sh

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?