Using Nextcloud’s command line


(1) Use Cron or Ajax to run Nextcloud background jobs
(2) Re-Scan your Nextcloud data
(3) Cleanup Nextclouds filecache
(4) Remove deleted files
(5) Disable or enable apps (e.g. two-factor authentication or gallery)
(6) List all config parameters and removes sensitive values
(7) All Nextcloud occ commands
(8) Upgrade your Nextcloud
(9) Enable/disable user
(10) Reset passwords


First change to your Nextcloud installation directory

cd /var/www/nextcloud

and – if necessary – set your cloud in maintenance mode:

sudo -u www-data php occ maintenance:mode --on

Don’t forget to set the maintenance mode to “off” when you have finished:

sudo -u www-data php occ maintenance:mode --off

(1) Use Cron or AJAX to run Nextcloud background jobs

sudo -u www-data php occ background:cron

sudo -u www-data php occ background:ajax

© c-rieger.de

(2) Re-Scan your Nextcloud data

For all users execute the following statement:

sudo -u www-data php occ files:scan --all -v

© c-rieger.de

Or execute a dedicated job for a specific user:

sudo -u www-data php occ files:scan <username> -v

[box type=”info”]files:scan will break shares, tags, comments – you have to re-enable them afterwards[/box]

(3) Cleanup Nextclouds filecache

sudo -u www-data php occ files:cleanup

© c-rieger.de

(4) Remove deleted files

sudo -u www-data php occ trashbin:cleanup <username>

© c-rieger.de

or don’t enter any username to cleanup all deleted files. In addition you may enhance the config.php either (‘trashbin_retention_obligation’ =>”):

auto – standard behaviour
D, auto – change the minimum days a file is kept with standard behaviour
auto, D – delete after a number of days, but earlier if space is required
D1, D2 – do not delete before, but definitely delete after a certain number of days
disabled – disable automatic deletion

'trashbin_retention_obligation' => 'auto, 7',

↑ Automatically delete files after 7 days, but earlier if space run low.

(5) Disable or enable apps (e.g. two-factor authentication or gallery)

Disable the 2FA for a specific user:

sudo -u www-data php occ twofactorauth:disable <username>

© c-rieger.de

Enable the 2FA for a specific user:

sudo -u www-data php occ twofactorauth:enable <username>

© c-rieger.de

Enable or disable e.g. the gallery app:

sudo -u www-data php occ app:enable gallery
sudo -u www-data php occ app:disable gallery

Please find further information here.

(6) List all config parameters and removes sensitive values

sudo -u www-data php occ config:list

© c-rieger.de

(7) All occ commands

To receive a list of all commands enter

sudo -u www-data php occ

(8) Upgrade your Nextcloud

Start the upgrade-Process (e.g. from 11.0.3 to 12.0):

sudo -u www-data php updater/updater.phar

Finally update the apps:

sudo -u www-data php php occ upgrade

(9) Enable/disable user

You can disable users via the occ command:

sudo -u www-data php occ user:disable username

Use the following command to enable the user again:

sudo -u www-data php occ user:enable username

Note that once users are disabled, their connected browsers will be disconnected.

(10) Resetting passwords

sudo -u www-data php occ user:resetpassword user

If your email settings were configured properly, an information email will be sent.


Carsten Rieger