by Ken Task.
No tool in core code nor plugin that I've found that will 'delete them all'.
Use query to find contenthash ... remove manually or via script then also remove the mdl_files row/record that referenced that .mbz file. (not fun, but doable).
Might check out Moosh
https://moosh-online.com/commands/
file-datacheck
Go through all files in Moodle data and check them for corruption. The check is to compare file's SHA to their file names.
moosh file-datacheck
file-dbcheckCheck that all files recorder in the DB do exist in Moodle data directory.
moosh file-dbcheck
file-deleteDelete Moodle files from DB and possibly move them to trash. File IDs
can be provided as arguments or on the standard input (with moosh
file-delete -s).
--flush option will remove the trashcan directory.
Example 1: Remove files with IDs 10,20 and 30.
moosh file-delete 10 20 30
Example 2: Remove all files with size greater than 100 bytes
moosh file-list -i 'filesize>1000' | moosh file-delete -s
Example 3: Flush trashcan
moosh file-delete --flush
Example 4: Remove all automated backups and reclaim the space
moosh file-list -i 'component="backup" AND filearea="automated"' | moosh file-delete -s
moosh file-delete --flush
file-listSearch and list files from mdl_files table. The argument should be a
valid SQL WHERE statement. Interesting columns of possible search
criterias are:
contextid, component, filearea, itemid, filepath, filename, userid,
filesize, mimetype, status, timecreated, timemodified.
You can also use some special values:
- course=NNN to list all files that relate to a course
The output will contain some defaults or nearly all possible file
information if "-a|--all" flag is provided. The meaning of the flags
column is (in order):
- mdl_files.status
- lowercase letter "d" if entry is a dicrectory
- "e" if external file
- "i" if a valid image
- "m" if time created and time modified differ
With "-i" option only IDs are returned. This can be used when pipe-ing into other file-related commands.
Use the -m option to list files that exsist on the {files} DB table but are missing from the file system,
and add -r option to remove them from the {file} DB table.
Example 1: Show all legacy files for a course, which context id is 15
moosh file-list "contextid=15 AND component='course' AND filearea='legacy'"
Example 2: Display full information on file with ID 17
moosh file-list -a id=162
Example 3: Show all files from course 6
moosh file-list course=6
Example 4: Super-combo. Get all course files and tar/bzip2 them up.
moosh file-list -i course=2 | moosh file-path -s -r | tar -C $(moosh config-get core dataroot) -T - -cjf files.tar.bz2
file-pathShow full or relative path in the filesystem to Moodle file(s). Files
can be identified by ID or hash (auto-detected) as arguments or on
stdin (-s option).
Example 1: Show path to a file with contenthash da39a3ee5e6b4b0d3255bfef95601890afd80709
moosh file-path da39a3ee5e6b4b0d3255bfef95601890afd80709
Example 2: Show paths to files with ID bewteen 100 and 200
moosh file-list -i 'id>100 AND id<200' | moosh file-path -s
Example 3: Like above but with no duplicates and show path relative to data root (-r)
moosh file-list -r -i 'id>100 AND id<200' | moosh file-path -s | sort | uniq
'spirit of sharing', Ken