NEWS

How to delete read-only files on Linux

How to delete read-only files on Linux

On Linux (Ubuntu or Mint distribution), to delete a computer file saved as read-only, there are several possibilities. If you are the creator, just change the permissions or use the sudo Terminal command as long as you are logged in as a system administrator. If you can't delete a file that still has write permission, you have to look at the support side, upstream therefore, in order to modify the permissions.

Change the permissions of a file


1 Run a Terminal window. A file that is read-only cannot be deleted unless you change its permission through Terminal, the command prompt, which opens with the key combination Ctrl+Alt+T.

The following method is effective in the event that you have a file that you have read or even write access to, but it is the administrator who has the privilege to delete it.

Of course, if you had already opened a Terminal window, you would not have to do anything, if not go to the next step.


2 Optionally change the directory. If your file is in a different directory than the one you are on, use the cd command. If the file to be deleted is in the Files folder of the Desktop directory, type cd Files if you are already on Desktop, otherwise cd /Desktop/Files.


3 Type the ls -al command. This is the one that displays the permissions of all the files present in the directory under consideration. The ls -l command allows the display of the names of the creators and the permissions of the files. With the ls -al command, there are also hidden files and folders in the directory.


4 Take a look at the permissions of your file. The permissions are visible on the left, just before the file name and is in the form: r--r--r--. In order, after the permissions, come the name of the owner of the file, then the name of the group ... if there is one!

r is the read permission, w is the write permission and finally, x is the execute permission.

The first three characters are the permissions granted to the creator of the file. In our example, r—, the creator of the file can only read the file without being able to edit it, execute it, let alone delete it.

The next three characters are the group permissions. If the group has write permission and you are a member of the group, then you will be able to edit the file, or even delete it.

The last three characters are the permissions of all other people who have access to the file.


5 Allow yourself the 2 permissions. To have read and write permissions, you need to use the following command :

chmod -v u+rw filename. The read permission r can be omitted, because you already have it a priori.

In case you are not the owner of the file, but you have been granted the privileges of a superuser, you could use, for the same result, the following command :

sudo chmod -v u+rw filename.

To find out the new permissions, run ls -al again.


6 Delete the file. To do this, use the command

rm filename. As a reminder, this command only works if you have write permission.

If you cannot delete the file while it is in write mode, the partition is still in read-only mode.



With the sudo command


1 Run a Terminal window. With a window manager, for this opening, use the keyboard combination Ctrl+Alt+T. Thanks to the sudo command, you will be able to delete a read-only file that could not have been deleted simply from your user account.

This method is to be used in case you are not the owner of the file and you want to delete this file without going through the change of permissions.

Of course, if you had already opened a Terminal window, you would not have to do anything, if not go to the next step.


2 Optionally change the directory. If your file is in a different directory than the one you are on, use the cd command. If the file to be deleted is in the Files folder of the Desktop directory, type cd Files if you are already on Desktop, otherwise cd /Desktop/Files.


3 Display the contents of the active directory. To see all the files in the directory as well as the owners and other permissions related to them, type the ls -al command.


4 Proceed to delete a file. The command is as follows :

sudo rm filename. You will be asked to enter the password that provides access to the root of the system. If you have it, then, the file will be instantly deleted.

If you cannot delete the file with the sudo command, it is because the partition, upstream therefore, has been set to be read-only. In this situation, you can always try the following method.



Fix a read-only file system error


1 Run a Terminal window. If, when deleting a file, you get the following error :

rm: cannot remove '(filename)': Read only file system, tell you that there are several possible explanations. With a window manager, open a window from the prompt by doing the keyboard combination Ctrl+Alt+T.

In case of remote connection, proceed directly to the next step.


2 Type the command df -h. It certainly allows to display the value of available disk space of the file systems, but above all it gives the mounting points: in front of each row and in the last column (Mounted on).


3 Type the mount grep point_de_montage command. Replace mount_point with the system mount point that seems to be blocking everything, for example, /media/usbdisk. If the file to be deleted is on an external hard drive or storage server, this media may have been set to read-only.

If ro appears in the results, it means that the file system is read-only. Reassemble the media in order to change its permissions: in the prompt, type the command :

mount -o remount,rw point_de_mount, then validate. Normally, the recalcitrant file should be able to be deleted.

If you have rw as the answer, it is because your disk is mounted with the 2 permissions, read and write, and normally the deletion of the file is possible. The problem then seems to lie in the drive's file system. Proceed to the next step.

If it is displayedmount-ro, it means that there is a problem with the file system and it is probably the media that has been mounted, for this or that reason, read-only. It is also possible that there is a problem with the file system of the drive. Proceed to the next step.


4 If the permissions are the ones you want, unmount the media. The command is as follows :

sudo umount device_name . Replace

device name by... the name of the media (disk, key...), for example, /dev/sdd1 for an SSD disk.

Since it is in use, it is not possible to unmount the root partition and as a result, you cannot check the file system of this partition (/), unless you restart in restore mode.


5 Run the command sudo fsck -n device_name. The support is then inspected in its entirety, but there are no modifications or repairs. The result that is displayed at the end indicates either that everything is in compliance (clean), or errors that are all listed.

In case of errors, before any operation, make a backup of your media in case things do not go as planned.



6 To fix permissions errors, type

sudo fsck device_name. If there were errors, you would be asked if you want to correct them.

We can't advise you too much to make a general backup before changing any permission, you never know what may happen!


7 Reassemble the bracket. Once the errors have been corrected, reassemble the drive so that you can proceed to delete the file. For a reassembly with read and write permissions, use the command :

mount -o remount,rw point_de_mount. Editing and deleting the file should normally be allowed.


Keywords : 

how to delete read only files on linux,how to remove read only files in linux,how to delete read only,how to delete read only directory in linux,how to delete a read only file system in linux,how to delete read-only file system mac,how to delete read only files on mac,how to delete read-only files on chromebook,delete read only file linux,delete read-only file system,delete read only file system linux,how to delete read only files,delete read only file,how to delete read only file in linux,how to remove a read only file in linux,how to remove read only file from linux,how to delete read only files in linux,how to remove read only file system in kali linux,how to edit read-only file in linux,how to delete only files not folders in linux,how to remove read only linux,how to remove a read only file system in linux,remove read only file system linux,how to remove read only file system linux,how to delete the read only files in linux,can you delete read only files,remove read-only file system

Comments
No comments
Post a Comment



    Reading Mode :
    Font Size
    +
    16
    -
    lines height
    +
    2
    -