How to delete a file or folder with OCC 🤔

Hello.
I just wonder how to (as mentioned in the subject headline), how to configure the delete command in the OCC command prompt:

How do you set the correct path to the file or folder that should be deleted?

Is it the full path or just the root www folder path in Linux?

We have installed Plesk CP on our server so Nextcloud runs on one of the user domains.

Thanks! :smiley:

1 Like

the path begins from within the data folder. So it should begin with the user-id of the user owning the file.

Example:

If you wants to delet a file example.txt in the Documents folder of user john, the call would be

occ files:delete john/files/Documents/example.txt

What I do not understand, is why you did not simply try it yourself. It is interactive and asks you if you (realy) wants to delete that file if the path was right or gives you a hint that the path could not be found:

root@box:~# occ files:delete john/files/Documents/example.txt
Delete /john/files/Documents/example.txt? [y/N] y

root@box:~# occ files:delete john/files/Documents/example.txt
file john/files/Documents/example.txt not found

You can enter the file-id instead of the path as well. Then it will ask you the same question with the path to that file. The file-id is a numeric token under which the file is registered in the filecache table of the database. You see the file-id in the url of the file if opened in your browser.

Example:

If the file-id of the file example.txt in the Documents folder of user john is 11290592, then you would see this:

root@box:~# occ files:delete 11290592
Delete /john/files/Documents/example.txt? [y/N]

h.t.h.


Much and good luck
ernolf

3 Likes

Thank you so much for replying and explaining this, it is very appreciated! :heart: :smiley:

That is because its our company server and I’m bit a afraid to mess things up. So I thought it was betters to ask to get it right from the start.

I was just about to ask that question on how to find the ID, but you explained that too which is great!

I did go to the data folder first manually and did try to delete the file, but it was not reflected in the Nextcloud UI which is why I figured/guess that you might need to delete the file (or folder for that sake), through OCC so it it deleted in the database too.

The reason behind this is because I have an issue with on file (its a manual backup copy of a wp-config.php file) , which Nextcloud refuses be to open, delete, move or copy with the error message:

image
image
image

No matter what I do it doesn’t make a difference and Nextcloud just refuse to do what I want (which in this case is delete the file)

You do not happen to have any idea of what is causing this and how to resolve this annoying issue?

so if you did delete the file on filesystem level, you need to tell the DB that the file is gone, rescan files occ files:scan --all

better that way, good thought :+1:

No. I just deleted it into the trash folder in Plesk and reloaded the UI.
occ files:scan --all
I didn’t know that command, thank you. I’m going to try that. :+1:
So that will refresh the database right?

yip, you should be fine after that

1 Like

Thank you very much and Merry X-mas! :smiley:

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