Remove managed files with 0 uses:
Find all of them with...
select file_managed.uri from file_managed left join file_usage on file_managed.fid = file_usage.fid where file_usage.fid is null;- Export a csv.
Use regex to escape spaces...
s/ /\\ /Use regex to mv files to a backup directory (e.g. "orphans")...
s/".*:\/\/\(.*\)"/mv web\/sites\/default\/files\/\1 ..\/orphansDelete them from the file_managed table with...
DELETE file_managed from file_managed left join file_usage on file_managed.fid = file_usage.fid where file_usage.fid is null;