Every time a file changes, Nextcloud can keep the old one as a version. For a folder with big files that change often, those versions pile up quickly. A cleanup of everything is blunt, so I like that you can aim it at one folder.
The command takes one or more user IDs, and --path narrows it to a directory. The path has to include the user ID and files/:
sudo -E -u www-data php occ versions:cleanup \
--path="/layla/files/Documents" layla
Without --path it deletes the stored versions of the listed users. Without any user it does it for all users, which is the one to be careful with.
Warning: this deletes versions for good. After it runs, nobody can restore an older state of those files from the web interface. I would run it only for a folder where the history has no value, such as a downloads or media folder, and I would check what people actually need first. There is no dry run flag in the manual, so the scope you give is the only safety.
For a softer approach there is versions:expire, which expires versions that exceed the retention period set by versions_retention_obligation in config.php. The docs say it only does something when a custom retention period is configured. With the default auto-expiration it exits and leaves the work to the background job.
As with other newer occ commands, the --path option is in the latest manual, so run occ help versions:cleanup to see whether your version has it.
Further reading: occ files commands, file versions (Nextcloud admin manual)
Going deeper: Guide: link Prowlarr to Sonarr and Radarr once, and stop typing indexers into every app