YetiShare core comes with a cli script to sanity check files on your main server aswell as external 'direct' file servers. This will ensure every file stored is active in the database plus clear any left over files which are no longer active and should have been removed.
See the guidance at the top of the following file for more information:
Another YetiShare user has also created a bash script to do the same. See the attached file_import.sh script. Please note that as this has been provided by a third party, we are unable to offer support on it's use. As with any changes, you should make sure you backup everything before running these scripts.