Skip to content

How to Resolve rm: cannot remove 'file': Permission denied

rm: cannot remove

Tried to remove a file from the current directory, but it failed with permission denied.

[erp@test ~]$ cd /backup/reports/
[erp@test reports]$ rm file
rm: cannot remove 'file': Permission denied

Let's see the permission and ownership of the file.

[erp@test reports]$ ls -l
total 9940
-rwxr-xr-x 1 erp erp 10176456 Jan  6 21:54 file

The user is the owner and the write permission is correctly set. It seems to be no problem.

Let's turn to check the current directory.

[erp@test reports]$ ls -al
total 9940
dr-xr-xr-x 2 erp erp       19 Jan  6 21:54 .
dr-xr-xr-x 3 erp erp       21 Jan  6 21:50 ..
-rwxr-xr-x 1 erp erp 10176456 Jan  6 21:54 file

As we can see, the current directory represented by a dot is owned by the user, which is no problem. However, the owner has no write permission, that's the problem.

Solution

To be enable to remove files in the directory, we add a write permission to the owner on the current directory.

[erp@test reports]$ chmod u+w .

We check the permission again.

[erp@test reports]$ ls -al
total 9940
drwxr-xr-x 2 erp erp       19 Jan  6 21:54 .
dr-xr-xr-x 3 erp erp       21 Jan  6 21:50 ..
-rwxr-xr-x 1 erp erp 10176456 Jan  6 21:54 file

Now we can remove the file without problem.

[erp@test reports]$ rm file
[erp@test reports]$ echo $?

Problem solved.

Leave a Reply

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