How to Delete Permission Denied File & Folder in Linux

Quick Insight

You can delete locked files on Linux by switching to root in the terminal. First, open the command line and run sudo su to gain full access. Next, type your password and press enter. Then, use the rm -rf command followed by the folder name. This method wipes the stuck item at once. As a result, you reclaim disk space and keep your desktop clean.

When you install any programs with root access on Linux-based operating systems, you may receive a Permission Denied error if you try to delete the remaining files or folders. As a result, you cannot delete the file or folder.

Deleting Permission Denied File & Folder in Linux

How to Delete an Undeleted File or Folder in Linux

For example, you are using the Linux Mint or Ubuntu operating system, and you have created a new file/folder on the desktop. Since you are logged in to the system with a non-root user, you can quickly delete the file/folder you created.

However, in some cases, when you install a program that requires root access, you may encounter files and folders that cannot be deleted anywhere or on the desktop. Therefore, when you try to delete these files and folders, you will usually receive a Permission Denied error.

On Linux, you can use Terminal to delete such files and folders that cannot be deleted. You can delete files that cannot be deleted using the Linux RM command by switching to Root in the Terminal.

How to Remove Files and Folders by Using Terminal on Ubuntu, Debian, Linux Mint, Kali Linux

We will use the Linux RM command to delete an indelible folder that we encountered on Linux Mint 18/19. On Linux, you can delete files, directories, and folders using the RM command.

To remove files on Linux or delete folders, follow the steps below.

Step 1

As you can see in the image below, there is a folder on Linux Mint that cannot be deleted. When you try to delete it, you will usually receive a Permission Denied error.

Try to delete the vmware-tools-distrib folder as follows.

vmware-tools-distrib

Step 2

You will receive a Permission Denied error, as in the image below.

Permission Denied Error

Step 3

Open the Terminal on Linux and execute sudo su to access Root, then type your root password and press Enter.

It is very normal to forget your root password if you have not used it for some time. Do not panic if you cannot get into the system for a short time. Let us look at a simple plan. You can reset your root password by starting in recovery mode. It is easier than you think. After you finish, you can go back to using the delete commands where you stopped.

sudo su

Step 4

On Linux, you can use the ls command to display the directory in your current location. To delete the undeleted folder, execute rm -rf vmware-tools-distrib.

rm -rf vmware-tools-distrib

rm -rf vmware-tools-distrib

Step 5

As soon as you execute the “rm -rf vmware-tools-distrib” command, you can see that the folder has been elected.

Deleting a Folder

Deleting a File That Cannot Be Deleted ⇒ Video

To delete an undeletable file or folder on Linux Mint 18/19, you can watch the video below and also subscribe to our YouTube channel to support us!

Video Thumbnail
Watch on YouTube

Frequently Asked Questions About Stubborn Files in Linux

Why do I suddenly get a ‘Permission Denied’ error when trying to delete an ordinary folder on the desktop?

This error is annoying but the reason is simple. That file or folder does not belong to you. Most likely, you created it with a program that ran with root privileges.
The system shuts the door on you to protect its own integrity. Your normal user account cannot touch something that root owns.
I compare this to a landlord-tenant relationship. You are the tenant, root is the landlord. A tenant cannot remove a boiler fixed to the wall. This is exactly why permission is denied.

When I type ‘sudo su’ in the terminal, nothing appears on the screen?

This is completely normal and a deliberate security measure. The Linux terminal does not even show stars (*) or dots while you type your password. This way, someone looking over your shoulder cannot see how many characters you typed.
You just enter your password correctly on the keyboard and press the Enter key without any hesitation. The system detects every keystroke of yours in the background.
Do not type and delete again and again just because there is nothing on the screen. Stay calm, enter the password, and move on.

What do the letters ‘rf’ do in the ‘rm -rf’ command you just mentioned? Can such a simple command crash the system?

Let me explain the power of these two letters. ‘r’ means recursive. When you try to delete a folder that has files inside, it first goes in and cleans everything one by one.
‘f’ means force. This parameter gives the system the instruction: ‘Do not ask me for confirmation, just do it and move on.’ It does not even skip write-protected files.
It only destroys the folder you target. But if you are not careful and accidentally target the root directory, that is when you toast the system. So, keep your eyes wide open when typing the command.

Do I have a chance to handle undeletable files with a file manager in the graphical interface without entering the terminal?

Of course you do, but it is a slightly more roundabout way. You need to open file managers like Nautilus or Nemo with root privileges.
To do this, you can press Alt + F2 and type ‘pkexec nemo’ or ‘sudo nautilus’. The window that opens now has root privileges. Right-clicking the file you want to delete and sending it to the normal trash does not work from this window.
You must permanently delete it directly by pressing Shift + Delete. Also, do not forget, be very careful in the window opened with this method. Damaging system files with a wrong click is very easy.

I deleted the file but it did not go to the trash at all, it just vanished. Did I do something wrong?

You did not do anything wrong, you just tasted the power of root. Nothing deleted with the ‘rm’ command ever visits the trash. The system instantly sends it to a digital black hole.
Your chance of getting it back is almost zero. That is why it is worth double-checking the folder name when typing the command.
If you deleted something critical and immediately stop writing to the disk, maybe professional data recovery tools can work. However, this process is troublesome and expensive. The best thing is to play it safe and take regular backups.

What can I do to avoid dealing with these leftover folders from software installations constantly?

Great question. The secret is to be a bit meticulous when removing programs. Your app store or the ‘apt remove’ command usually leaves these leftovers behind.
Instead, you should use the ‘apt purge program-name’ command. This command not only deletes the program but also sweeps away all the configuration files it left behind.
Additionally, avoid using your desktop as an installation area. Open .deb packages or .tar.gz archives in the Downloads folder and compile them there. As a result, your desktop stays tidier and you do not have to deal with these stubborn guests.

The package manager can sometimes get stuck in the middle of a job. Unfinished installations are very annoying. If you do not notice this, uninstalling will also freeze. The good news is there are very clear ways to fix problems with the dpkg package manager.

Conclusion

In this article, we have examined step-by-step how to delete permission-denied files or folders. Thanks for following us!

They'll Thank You for Discovering This Guide!

Ready to do your loved ones a huge favor with just one click? Knowledge grows as it is shared.

10 People Shared Their Experience

  1. thanks

    1. You’re welcome!

  2. thank you !

    1. You’re welcome!

  3. thanks for the helpful article.

    1. You’re welcome. Thanks for your comment.

  4. Thanks for the article !!!
    Such a helpful and easy to understand Great work !!!

    1. You’re welcome!

  5. Thanks

    1. You’re welcome!

Share Your Opinion