How to Delete Read-Only Files on Linux

Change file permissions

How to Delete Read-Only Files on Linux Picture 1

Open a terminal window. If a file that you own is set to read-only, you cannot delete the file unless you manually set it to write permission. If you use a window manager, press Ctrl + Alt + T to open a terminal window now.

Use this method if you want to delete a file that you own but do not have permission to delete (for example, if you are the owner or in a group with permission to read the file).

If you are logged in remotely and are viewing the command console, proceed to the next step.

How to Delete Read-Only Files on Linux Picture 2

Use cd to enter the directory with the file to be deleted. For example, if the file you want to delete is stored in the documents folder of the 'home' folder, type cd documents or cd /home/username/documents.

How to Delete Read-Only Files on Linux Picture 3

Use ls -al to see the permissions of the files in the directory. Using ls -l shows you a list of files in the directory, along with the owners of each file and their permissions. Adding a to ls -l also shows you hidden files and folders.

How to Delete Read-Only Files on Linux Picture 4

View the permissions of the file you want to delete. Permissions appear before the filename, such as: r--r--r--. The owner's name is shown at the back, followed by the group name.

r is read, w is write, and x is execute.

The first three characters in the access permission (for example r--) are the access permission of the file owner. So, in this example, the file owner has read permission, but not write, execute, or delete permission to the file.

The next three characters are group access. If you are a member of a group and that group has write permission to the file, you can delete the file even if you are not the owner.

The last three characters are universal access, which is meant for everyone.

How to Delete Read-Only Files on Linux Picture 5

Use chmod -v u+rw filename to give you read and write permissions. You can omit r if you already have read permission. Once you have write permission, you can delete the file.

If you are not the owner of the file but have root access to the system, you can use sudo chmod -v u+rw the filename to give you the proper permissions.

To see the file's new permissions, use the ls -al command again.

How to Delete Read-Only Files on Linux Picture 6

Use rm filename to delete the file. You now have write permissions and can delete files.

If you can't delete the file after gaining write access, perhaps the partition is read-only. Learn how to fix the read-only filesystem to fix the problem.

Using sudo

How to Delete Read-Only Files on Linux Picture 7

Open a terminal window. You can use the sudo command to delete read-only files that you cannot delete with your user account. If you want to use the window management tool, press Ctrl + Alt + T to open a terminal window right away.

Use this method if you are not the owner of the file to be deleted and you want to delete the file instead of changing the permissions.

If you are logged in remotely and are viewing the command console, proceed to the next step.

How to Delete Read-Only Files on Linux Picture 8

Use cd to enter the directory of the file you want to delete. For example, if the file you want to delete is stored in the documents folder of the 'home' folder, you would use the command cd documents or cd /home/username/documents.

How to Delete Read-Only Files on Linux Picture 9

Use ls -al to view the contents of the directory. This command will display all files in the current directory, along with the owner name and permissions of each file.

How to Delete Read-Only Files on Linux Picture 10

Use sudo rm filename to delete the file. You will be asked for a password to use the highest level of access. Once the password is accepted, the read-only file will be deleted.

If you can't delete the file with sudo, the partition is probably read-only. Learn how to fix the read-only filesystem to fix the problem.

Fix read-only file system

How to Delete Read-Only Files on Linux Picture 11

Open a terminal window. There are several reasons why you might get the error rm: cannot remove '(filename)' : Read only file system when you want to delete a file. Start by pressing Ctrl + Alt + T to open a terminal window if you use a window management tool.

If you are logging in remotely, go to the next step.

How to Delete Read-Only Files on Linux Picture 12

Use df -h to see all mounted devices. You need to know the exact mount point of the drive that is causing you problems. This shows you the entire mounted drive.

How to Delete Read-Only Files on Linux Picture 13

Use the mount command. Replace the mount point with the actual mount point, such as /media/usbdisk. If you want to delete files on a USB or network drive, such as old backup data, the drive where the file is stored will be mounted with read-only access.

If you see ro in the results, the file system is read-only. Mounting the drive should fix the problem. To do this, you would use the command mount -o remount,rw the mount point. You can delete the file immediately afterwards.

If the access is rw, the drive is mounted with read-write access, and you can delete files without problems. This usually means that there is a problem with the file system on the drive. Let's continue with the remaining steps.

If you see remount-ro, the filesystem is in trouble and the drive is mounted with read-only access to limit damage. It also means that there is a problem with the file system on the drive. Let's continue with the remaining steps.

How to Delete Read-Only Files on Linux Picture 14

If access is set correctly, unmount the drive. To do this, you would use the command sudo umount device . Replace device with the device name, such as /dev/sdd1.

Since you cannot unmount the root filesystem, you cannot check the root partition's filesystem unless you are booted into recovery mode. If the error occurs on the root filesystem, boot into recovery mode first.

How to Delete Read-Only Files on Linux Picture 15

Use the command sudo fsck -n device to check the drive. This is an operation that checks the integrity of the drive without making any further changes. If the drive is working properly, you should see "clean" in the results. If the drive has an error, the information will also be displayed here.

If you see errors, back up the drive before continuing in case the filesystem cannot be repaired.

How to Delete Read-Only Files on Linux Picture 16

Use the command sudo fsck device to fix the error. If there are errors, you will be asked to correct them.

Even if you can fix the error, back up your data in case the drive fails.

How to Delete Read-Only Files on Linux Picture 17

Mount the drive after fixing the error. If you can fix the error, mounting the drive will assist you in deleting the file. Use mount -o remount,rw mount point to make sure the drive is mounted with read and write access. You can edit and delete files on the drive immediately afterwards.

4 ★ | 61 Vote

May be interested

  • File Management in Unix / LinuxFile Management in Unix / Linux
    all data in unix is ​​organized in files. all files are organized in folders. these directories are organized in a tree structure that is called the file system.
  • Is it possible to run .exe files on Linux?Is it possible to run .exe files on Linux?
    you don't need to trade the appeal of windows software for the stability, security, ease of customization (and even great classic appearance) of linux. in this article, you will be shown how to run windows exe (possibly executable) files and software using the linux operating system. these methods can be applied to any linux distribution, including ubuntu, kali linux, centos and many others.
  • How to Delete DLL FilesHow to Delete DLL Files
    to delete unwanted or corrupt .dll files, you will need to find them by making hidden files visible, unregister them through command prompt, and then delete them manually from their source folder. your pc's dynamic link library files store...
  • How to create and delete folders in Linux TerminalHow to create and delete folders in Linux Terminal
    folders are essential for your linux operating system because they contain files you may use often or that the system needs to function correctly.
  • How to Delete Files That Cannot Be DeletedHow to Delete Files That Cannot Be Deleted
    this wikihow teaches you how to delete regular files that you can't seem to delete on your computer. most of the time, files you can't delete are being used by a program or a service; you can start your computer in safe mode to prevent the...
  • How to automatically delete Zip files after extracting on MacHow to automatically delete Zip files after extracting on Mac
    there are many ways to reduce clutter and keep your mac neat. you can use powerful software like clean my mac, or take advantage of apple's existing features to keep your hard drive neat.
  • How to delete, replace or edit links in PDF documents with PDF Link EditorHow to delete, replace or edit links in PDF documents with PDF Link Editor
    many pdf documents containing urls can be corrupted over time and you want to delete or replace them with active links. please read the following article to learn how to delete and replace links in pdf files.
  • How to delete 'iOS Files' which is taking up your Mac's memory?How to delete 'iOS Files' which is taking up your Mac's memory?
    do you have some mysterious 'ios files' taking up too much of your valuable mac memory? maybe you do not need them anymore, the article below helps you completely eliminate those files.
  • How to read EPUB files on your computer, software to read EPUB filesHow to read EPUB files on your computer, software to read EPUB files
    how to read epub files on your computer, software to read epub files epub is one of the formats of ebook, which is also quite popular when you download documents or books on the internet and you may come across this format. of course to read
  • How to use pandoc to convert files on LinuxHow to use pandoc to convert files on Linux
    you can use pandoc on linux to convert over 40 different file formats. you can also use it to create a simple docs-as-code system by writing to markdown, saving with git and exporting it in any supported format.