PDF download Download Article PDF download Download Article

If you want to delete a file that has read-only permissions in Linux, you have a few options. If the file belongs to you, you can either change the file's permissions or use the sudo command to delete the file as root. But if you're trying to delete a file that has write permissions and still can't delete it (or you see a "Read Only File System" error), you may need to remount the drive with proper permissions. We'll show you how to remove any read-only file on any Linux distribution, including Ubuntu and Linux Mint.

Deleting a Read Only File in Linux

If it’s your file, give yourself write permissions by writing chmod -v u+rw filename . Then, you can delete the file. If you don’t own it, you can use sudo chmod -v u+rw filename to get permission, then use rm filename to delete the file.

Method 1
Method 1 of 3:

Changing File Permissions

PDF download Download Article
  1. If a file you own is read-only, you won't be able to delete it unless you give yourself write permission for that file. If you're using a window manager, press Ctrl + Alt + T to open a terminal window now. [1]
    • Use this method if you're trying to delete a file that belongs to you but (e.g., you're the owner or in a group that has access to read the file) but don't have permission to delete it.
    • If you're signed in remotely and already at a command prompt, just skip to the next step.
  2. For example, if the file you want to delete is inside a folder called documents in your home directory, you'd use cd documents or cd /home/ username /documents .
    Advertisement
  3. Using ls -l displays a list of files in the directory, along with the owner of each file and its permissions. [2] Adding the a to ls -l also shows hidden files and folders in the directory.
  4. The permissions for a file appear before its name like this: r--r--r-- . The owner's name appears after it, followed by the group name.
    • r is read permissions, w is write permissions, and x is execute permissions.
    • The first three characters in the permissions (in this example, r-- ), are the file owner's permissions. So, in this example, the owner of the file only has read permissions, which means they can't write to, execute, or delete the file. [3]
    • The second three characters are group permissions. If you're a member of a group and that group has write permissions to the file, you'll be able to delete it even if you're not the owner.
    • The third three characters are world permissions, which is everyone else.
  5. You can omit the r if you already have read permissions. Once you have write permissions, you'll be able to delete the file.
    • If you're not the file owner but have root access to the system, you can use sudo chmod -v u+rw filename to give yourself the right permissions. [4]
    • To see the file's new permissions, run ls -al again.
  6. Now that you have write permissions on the file, deleting it will be simple.
  7. Advertisement
Method 2
Method 2 of 3:

Using sudo

PDF download Download Article
  1. You can use the sudo command to delete a read-only file that you aren't able to delete with your user account. If you're using a window manager, press Ctrl + Alt + T to open a terminal window now.
    • Use this method if you are not the owner of the file you want to delete and you'd rather just delete the file instead of first changing its permissions.
    • If you're signed in remotely and already at a command prompt, just skip to the next step.
  2. For example, if the file you want to delete a file inside a folder called documents in your home directory, you'd use cd documents or cd /home/ username /documents .
  3. This command will display all of the files in the current directory, as well as each file's owner and permissions.
  4. You'll be prompted to enter your password to obtain root-level permissions. Once your password is accepted, the read-only file will be deleted.
  5. Advertisement
Method 3
Method 3 of 3:

Fixing the Read Only File System Error

PDF download Download Article
  1. If you're trying to delete a file and getting an error that says rm: cannot remove '(filename)' : Read only file system , there are a few possible causes. Start by pressing Ctrl + Alt + T to open a terminal window if you're using a window manager.
    • If you're signed in remotely, just move to the next step.
  2. You'll need to know the exact mount point of the drive that's giving you trouble. This displays all mounted drives.
  3. Replace mount point with the actual mount point, e.g., /media/usbdisk . If you're trying to delete a file on a removable disk or network drive, such as an old backup, the disk where the file is stored might be mounted as read-only.
    • If you see ro in the results, the file system is read-only. Remounting the drive should fix the error. To do so, use mount -o remount,rw mount point . You can then delete the file.
    • If the permissions are rw , the disk is mounted with read-write permissions, which means you should be able to delete files without problems. This usually means there's a problem with the file system on the drive. Continue with this method.
    • If you see remount-ro , this means the there's a problem with the file system and the drive was remounted as read-only to limit additional damage. This also means there's a problem with the file system on the drive. Continue with this method.
  4. To do this, run sudo umount device . Replace device with the device name, e.g., /dev/sdd1 .
    • Since you can't unmount a root file system, you can't check the file system of the root partition unless you're booted into recovery mode. If the error is on the root file system, boot into recovery mode first.
  5. This checks the integrity of the drive without making any changes. If the drive is okay, you'll see "clean" in the results. If there are errors, you will see them.
    • If there are errors, back up the drive before you continue in case the file system cannot be repaired.
  6. If there are errors, you'll be prompted to correct them.
    • Even if you are able to correct errors, make a backup just in case the drive is dying.
  7. If you were able to repair the errors, remounting the drive will make it so you can delete your files. Use mount -o remount,rw mount point to ensure the drive is remounted with read and write permissions. You should then be able to modify and delete files on the drive.
  8. Advertisement

Expert Q&A

Ask a Question
      Advertisement

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!

      Expert Interview

      Thanks for reading our article! If you'd like to learn more about Computer Networking, check out our in-depth interview with Stan Kats .

      About This Article

      Thanks to all authors for creating a page that has been read 151,080 times.

      Is this article up to date?

      Advertisement