How to safely mass delete files with regex?

Steps to reproduce

  1. Attempt to remove manually from /var/www/owncloud/data/user/files.
  2. Running occ files:scan --path="/Path/To/Directory/With/Deleted/Files"

Expected behaviour

File should be deleted from web interface.

Actual behaviour

File is still there, but I cannot download the file (as if file does not exist).

Server configuration

Operating system: Ubuntu 20.04 LTS

Web server: Apache/2.4.41 (Ubuntu)

Database: mysql Ver 8.0.31

PHP version: PHP 7.4.32

ownCloud version: (see ownCloud admin page) ownCloud 10.11.0

Description of Problem

I have 100+ directory that has date as its name, I want to remove directory from date x to date y, this could be done easily using command line (e.g.; rm -r 2023-10*). I tried to delete manually from /var/www/owncloud/data, it doesn’t seem to work (file is still appear as available from web interface, upon downloading I get internal server error telling file doesn’t exist).

Is there any preferred way to bulk delete file with regex ? I can only tick each file manually within web interface to be deleted, obviously this will take long.

Hi,

You could mount the webdav of the user you want to delete these directories, and then run you rm command.

Once done, be careful with the trashbin, depending on your policy it could keep a lot of those directories and you wouldn’t gain any free space.

If you delete files directly in the backend you need to run a filescan to inform ownClouds metadata database it can drop these file entries.

I have execute this after I delete, does this count as file scan ?

1 Like

Oh sorry I didn’t notice that you mentioned that.

Be careful with absolute paths, for me the output looks like so when I try to run it that way:

occ files:scan -p "/mnt/owncloud/data/eneubauer/files/vids/"

Scanning files for 1 users
Unknown user 1 mnt

+---------+-------+--------------+------------------+
| Folders | Files | Elapsed time | Items per second |
+---------+-------+--------------+------------------+
| 0       | 0     | 00:00:00     | 0                |
+---------+-------+--------------+------------------+

This indicates that the command wasn’t successful.

The correct way to run it is:

occ files:scan -p "eneubauer/files/vids/"

Scanning files for 1 users
Starting scan for user 1 out of 1 (eneubauer)

+---------+-------+--------------+------------------+
| Folders | Files | Elapsed time | Items per second |
+---------+-------+--------------+------------------+
| 15      | 31    | 00:00:00     | 188              |
+---------+-------+--------------+------------------+
# occ files:scan -p "/eneubauer/files/vids/" also works
2 Likes

Thanks it is working

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.