There's a way to know how many files are on the system?

I have an OwnCloud running for some years now with different accounts of other people uploading and sharing files between them.

I wanted to know if there’s a faster way to know the file count than going to each folder and sum all the files manually. I don’t know if in the DB I can see how many files are.

Sorry for the broad question, I’m a beginner in these subjects.

It would be good to know what you are trying to achieve. I doubt that the number of single files will help you so I am guessing you want to know ho much space each user is using, correct?

Not really, the client (I don’t know exactly why) wants to know how many files are up there already.

Do you want to count all the files owner independent?

Something like this could be achieved directly in the DB:

mysql> select count(fileid) from oc_filecache;
| count(fileid) |
| 8193 |
1 row in set (0.17 sec)


This is going to show you not only the files but also every version of a file, all files in the trashbin, external files, folders and other ownCloud internal files like for example keys.

I had a quick look in the database and to exclude folders, but include all else you could run

SELECT count(fileid) FROM oc_filecache WHERE mimetype!=2;

To exclude other types of folders the easiest way is the following:

SELECT count(fileid) from oc_filecache WHERE mimetype!=2 AND path NOT LIKE 'files_trashbin%' AND path NOT LIKE 'files_versions%';

You would have to play around a little bit with the output and see what other ownCloud internal folders are still being displayed in your case and exclude them.

A different and rather quick way on the command line would be:

find /path/to/owncloud/data/*/files -type f | wc -l

This should directly only display local files in the filesystem and no versions or trashbin.

1 Like

I don’t think it’s possible through ownCloud. In the DB you can have versions, files in the trashbin, thumbnails and maybe other files not within the “normal” files view.

You also need to consider that different users might have different views of the file system. While this won’t affect the primary storage, this might happen with external storages, specially if users access with different accounts.
Basically, X users accessing to Y files in a shared external storage might create X*Y entries (depending on the visibility of those files per user).

You might want to check it directly in the storage