Removing a File That Is Not Write-Protected
First, we will attempt to remove a file that is not write-protected just to see the difference between its removal and the removal of a write-protected file. We have a file named “test.txt” in our Home directory that is not write-protected. This file is shown in the following image:
We will attempt to remove this file by using the command shown below:
This file will be removed very easily without displaying any output on the terminal as shown in the following image:
For confirming if the specified file has been successfully removed or not, we will use the “ls” command to list the contents of our Home directory. You can confirm from the output of this command shown in the image below, that the “test.txt” file no longer exists in our Home directory.
Making a File Write-Protected
Now, we will create another file named “test.txt” in our Home directory. You can confirm that this file is present in our Home directory by looking at the following image:
To make this file write-protected, we will run the command shown below:
This command will not display any output on the terminal.
To confirm if this file is write-protected, we will try to remove it with the following command:
The output of this command shown in the image below, implies that this file is now write-protected and hence, it cannot be removed this way.
You can even try using the “-f” flag with the “rm” command for removing this file forcefully. However, you will still not be able to remove a write-protected file as shown in the following image:
Removing a Write-Protected Regular File
The only thing that we can do to remove the said file is by changing its permissions with the command shown below:
This command will simply remove the “write-protected” restriction from this file.
Now, we will remove it with the following command:
This time, this command will be executed successfully without displaying any error message as shown in the image below:
For confirming if the specified file has been removed successfully or not, we will make use of the “ls” command. You can confirm from its output shown in the following image that the file “test.txt” no longer exists in our Home directory.
Conclusion
By using this guide, you can easily attempt to remove any of your write-protected files while working on a Linux Mint 20.3 system. All you need to do is to change the permissions of this file by following the prescribed method and then you can simply remove it through the regular way. Check out Linux Hint articles for more guides and tips.