Purging a huge amount of files from public storage.
1
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:
- build your file list using tinker or an SQL query (you just need the
disk_name
column) - dump that list in a file called
fileList.txt
- 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
- run the following command in your terminal:
cat fileList.txt | bash bulk_purge.sh
There are no comments yet
Be the first one to comment