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
(11) Add new User to a particular group
(12) Enable/disable user


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 13.0.6 to 14.0.1):

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

Finally update the apps:

sudo -u www-data php /var/www/nextcloud/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.

(11) Add user(s) to a particular group

sudo -u www-data php occ user:add username -g groupname

(12) Enable/Disable User(s)

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


Enjoy your personal data in your secured and hardened Nextcloud-Server!

Don’t forget to backup your Nextcloud

Find more instructions here: Nextcloud Backup and Restore



Carsten Rieger

Carsten Rieger

Carsten Rieger is a senior system engineer in full-time and also working as an IT freelancer. He is working with linux environments for more than 13 years, an Open Source enthusiast and highly motivated on linux installation and troubleshooting. Mostly working with Debian/Ubuntu Linux, Nginx and Apache web server, MariaDB/MySQL/PostgreSQL, PHP, Cloud infrastructure (e.g. Nextcloud) and other open source projects (e.g. Roundcube) and in voluntary work for the Dr. Michael & Angela Jacobi Stiftung for more than 6 years.

3 Responses

  1. David Stachowiak says:

    Hallo,
    gibt es eine Möglichkeit das Update ohne Bestätigung durchführen zu können? Das ich es quasi voll automatisieren kann.

  2. Rainer says:

    Hi Carsten,

    gibt es auch die Möglichkeit, bei allen oder auch einzelnen Usern den kompletten Inhalt von Dateien/Ordnern als Administrator zu löschen? Also nicht nur, wenn sich die Dateien schon im Papierkorb befinden, sondern wenn sie noch
    ganz normal beim Benutzer Verfügbar sind? Es geht darum, dass der Platz auf dem Server nicht vollaufen soll, wenn die Mitarbeiter vergessen, ihre alten Dateien zu löschen.

    Grüße
    Rainer

Leave a Reply

Your email address will not be published. Required fields are marked *