What does tmp mean?
Tmp is an abbreviation of temporary. So the tmp folder is a folder intended for temporary files. Every operating system uses such a folder, and in facts needs it. So does Drupal. Drupal by default attempts to store files in your operating system's tmp folder. On Linux this is /tmp
, on Windows C:\Windows\Temp
. You can check and change this setting in Configuration > Media > File System
. If your temporary directory is set to one of these standard paths, you should assume it is not only Drupal's files, but files of the operating system and several other programs (Apache sessions, Drush downloads, installation packages).
If it is on a custom path, or in the case of the OP: /sites/default/files/tmp/
(Drupal's fallback path) it should contain only Drupal files.
So what kind of files does Drupal store there?
In general Drupal stores all uploaded files in the temporary folder first. If something goes wrong (eg. the connection with the client is interrupted) there is a corrupted file on the server. Keeping these files in a temporary folder and only moving them after the whole file was transferred, ensures there will be no damaged or unneeded files in your public files directory sites/default/files
.
This also includes modules and translation downloads, some js files (probably used in aggregation) and several other files.
There is no real list of all files Drupal stores in tmp, because contributed modules might choose to store a file there as well. Possible use cases for this could be file generation on demand (eg. a module that packages a custom selection of files into a zip file and offers it as download. It is unlikely the same file will be used more than once and there is no real benefit in storing it).
Can I safely remove the files?
Well yes and no... The idea of temporary files is that they are, well... temporary. They are generally used directly after they are created and might no longer be needed. But since all programs can write to tmp, it is a reasonable assumption not all programmers played by the rules, or some files might in fact still be in use.
Should I remove the files?
Drupal performs several cleanups on its own during cron runs (assuming cron is set up and working). Uploaded files that were not saved permanently will be removed during system_cron().
Old modules downloads are handled by update_delete_file_if_stale() (via update_clear_update_disk_cache() and update_cron()).
These cleanups are set to clean up files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE (6 hours), but the actual time depends on the cron interval. (If cron only runs every 12 hours, it can take up to 12 hours before the files are removed).
In most cases there should be no need to remove the files manually. If in some cases cron doesn't remove (all) files, you might attempt to remove them by hand. But make a backup first!
If your folder is shared with your operating system's folder, you might want to use your operating system's tools for it (Windows users can clean the temporary files with the Disk Cleanup
tool. (Some Linux distributions clean the folder during system reboot, some don't.)
When the tmp folder is on a custom (non-operating system) path, as is the case with the OP, it should be relatively save to empty the folder by hand. Make sure your webserver (Apache, Nginx) is stopped, so no user of cron task will be touching the files. Then delete the stale files (older than 6 hours) manually.
Conclusion
If your system is setup properly and cron is working, there should be no need to clean these files, as they are removed automatically. If it doesn't happen, you can remove them manually, but keep above conditions in mind. It might still go wrong, so always make a backup!