Drupal 8, we can programmatically delete our unused files(assets) easily. we just have to write the code in custom module file in `hook_cron` function. After put the code and clear the cache whenever you hit the cron manually or automatically will run this code will execute.
Code:
/**
* override hook_cron()
*/
function mymodule_cron() // mymodule will replace with module name
{
// get all files ids
$fids = Drupal::entityQuery('file')->execute();
$file_usage = Drupal::service('file.usage');
// loop all fids and load files by fid
foreach ($fids as $fid) {
$file = Drupal\file\Entity\File::load($fid);
$usage = $file_usage->listUsage($file);
// check if file not used
if (count($usage) == 0) {
$file->delete();
}
}
}