• About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy Policy
  • Change the purpose of use

Tnhelearning.edu.vn - Various useful general information portal

  • Photo
  • Bio
  • How To
  • Tech

How to Delete Read-Only Files on Linux

February 7, 2024 by admin Category: How To

You are viewing the article How to Delete Read-Only Files on Linux  at Tnhelearning.edu.vn you can quickly access the necessary information in the table of contents of the article below.

X

This article was co-written by Stan Kats. Stan Kats is a technology engineer, chief executive officer and chief technology officer at STG IT Consulting Group in West HPlywood, California. Stan provides comprehensive technology solutions to businesses through IT services and to individuals through his consumer services company Stan’s Tech Garage. He holds a bachelor’s degree in international relations from the University of Southern California. He started his career at a Fortune 500 company. Stan founded his own companies to provide enterprise-level professional services to individuals and small companies.

This article has been viewed 2,178 times.

There are several ways to help you delete files read-only on Linux. If it’s a file you own, you can change the file permissions or use the sudo command to delete the original file. However, if you cannot delete the file with write permissions (or see the “Read Only File System” error message), you need to change the drive with the appropriate permissions. This article will show you how to delete read-only files on any Linux distribution, including Ubuntu and Linux Mint.

Table of Contents

  • Steps
    • Change file permissions
    • Using sudo
    • Fix read-only file system

Steps

Change file permissions

Image titled Delete Read Only Files in Linux Step 1

Image titled Delete Read Only Files in Linux Step 1

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/7/7c/Delete-Read-Only-Files-in-Linux-Step-1.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-1.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/7/7c/Delete-Read-Only-Files-in-Linux- Step-1.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-1.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
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. 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 that has permission to read the file).
  • If you are logged in remotely and are viewing the command console, proceed to the next step.
Image titled Delete Read Only Files in Linux Step 2

Image titled Delete Read Only Files in Linux Step 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/8/80/Delete-Read-Only-Files-in-Linux-Step-2.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-2.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/8/80/Delete-Read-Only-Files-in-Linux- Step-2.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-2.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
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 .
Image titled Delete Read Only Files in Linux Step 3

Image titled Delete Read Only Files in Linux Step 3

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/7/7b/Delete-Read-Only-Files-in-Linux-Step-3.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-3.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/7/7b/Delete-Read-Only-Files-in-Linux- Step-3.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-3.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
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 directories.
Image titled Delete Read Only Files in Linux Step 4

READ More:   How to Fix a Scratched CD

Image titled Delete Read Only Files in Linux Step 4

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/7/76/Delete-Read-Only-Files-in-Linux-Step-4.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-4.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/7/76/Delete-Read-Only-Files-in-Linux- Step-4.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-4.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
View the permissions of the file you want to delete. The permissions show up 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 permissions (for example r-- ) are the permissions 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.
Image titled Delete Read Only Files in Linux Step 5

Image titled Delete Read Only Files in Linux Step 5

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/c/c7/Delete-Read-Only-Files-in-Linux-Step-5-Version-3.jpg/v4-728px- Delete-Read-Only-Files-in-Linux-Step-5-Version-3.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/c/c7/Delete-Read- Only-Files-in-Linux-Step-5-Version-3.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-5-Version-3.jpg”,”smallWidth”:460 ,”smallHeight”:345,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
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 access.
  • To see the new file permissions, use the ls -al command again.
Image titled Delete Read Only Files in Linux Step 6

Image titled Delete Read Only Files in Linux Step 6

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/6/6c/Delete-Read-Only-Files-in-Linux-Step-6.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-6.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/6/6c/Delete-Read-Only-Files-in-Linux- Step-6.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-6.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
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 file system to fix the problem.

Using sudo

Image titled Delete Read Only Files in Linux Step 7

Image titled Delete Read Only Files in Linux Step 7

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/e/e8/Delete-Read-Only-Files-in-Linux-Step-7.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-7.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/e/e8/Delete-Read-Only-Files-in-Linux- Step-7.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-7.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
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 permissions.
  • If you are logged in remotely and are viewing the command console, proceed to the next step.
Image titled Delete Read Only Files in Linux Step 8

Image titled Delete Read Only Files in Linux Step 8

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/a/a3/Delete-Read-Only-Files-in-Linux-Step-8.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-8.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/a/a3/Delete-Read-Only-Files-in-Linux- Step-8.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-8.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
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 .
Image titled Delete Read Only Files in Linux Step 9

Image titled Delete Read Only Files in Linux Step 9

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/6/6c/Delete-Read-Only-Files-in-Linux-Step-9.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-9.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/6/6c/Delete-Read-Only-Files-in-Linux- Step-9.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-9.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
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.
Image titled Delete Read Only Files in Linux Step 10

READ More:   How to Deal with a Cheating Partner

Image titled Delete Read Only Files in Linux Step 10

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/6/66/Delete-Read-Only-Files-in-Linux-Step-10.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-10.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/6/66/Delete-Read-Only-Files-in-Linux- Step-10.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-10.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
Use sudo rm filename to delete the file. You will be asked to enter 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 file system to fix the problem.

Fix read-only file system

Image titled Delete Read Only Files in Linux Step 11

Image titled Delete Read Only Files in Linux Step 11

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/a/ae/Delete-Read-Only-Files-in-Linux-Step-11.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-11.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/a/ae/Delete-Read-Only-Files-in-Linux- Step-11.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-11.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
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.
Image titled Delete Read Only Files in Linux Step 12

Image titled Delete Read Only Files in Linux Step 12

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/f/fe/Delete-Read-Only-Files-in-Linux-Step-12.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-12.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/f/fe/Delete-Read-Only-Files-in-Linux- Step-12.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-12.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
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 will show you the entire mounted drive.
Image titled Delete Read Only Files in Linux Step 13

Image titled Delete Read Only Files in Linux Step 13

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/4/44/Delete-Read-Only-Files-in-Linux-Step-13.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-13.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/4/44/Delete-Read-Only-Files-in-Linux- Step-13.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-13.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
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 to point the mount . 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.
Image titled Delete Read Only Files in Linux Step 14

Image titled Delete Read Only Files in Linux Step 14

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/4/4f/Delete-Read-Only-Files-in-Linux-Step-14.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-14.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/4/4f/Delete-Read-Only-Files-in-Linux- Step-14.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-14.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
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.
READ More:   How to Distinguish the Sex of a Parrot
Image titled Delete Read Only Files in Linux Step 15

Image titled Delete Read Only Files in Linux Step 15

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/a/a0/Delete-Read-Only-Files-in-Linux-Step-15.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-15.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/a/a0/Delete-Read-Only-Files-in-Linux- Step-15.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-15.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
Use the command sudo fsck -n device to check the drive. This is an operation that checks the integrity of the drive without making 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 an error, back up the drive before continuing in case the filesystem can’t be fixed.
Image titled Delete Read Only Files in Linux Step 16

Image titled Delete Read Only Files in Linux Step 16

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/7/7c/Delete-Read-Only-Files-in-Linux-Step-16.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-16.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/7/7c/Delete-Read-Only-Files-in-Linux- Step-16.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-16.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
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.
  • Image titled Delete Read Only Files in Linux Step 17

    Image titled Delete Read Only Files in Linux Step 17

    {“smallUrl”:”https://www.wikihow.com/images_en/thumb/c/cb/Delete-Read-Only-Files-in-Linux-Step-17.jpg/v4-728px-Delete-Read- Only-Files-in-Linux-Step-17.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/c/cb/Delete-Read-Only-Files-in-Linux- Step-17.jpg/v4-728px-Delete-Read-Only-Files-in-Linux-Step-17.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
    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.
  • X

    This article was co-written by Stan Kats. Stan Kats is a technology engineer, chief executive officer and chief technology officer at STG IT Consulting Group in West HPlywood, California. Stan provides comprehensive technology solutions to businesses through IT services and to individuals through his consumer services company Stan’s Tech Garage. He holds a bachelor’s degree in international relations from the University of Southern California. He started his career at a Fortune 500 company. Stan founded his own companies to provide enterprise-level professional services to individuals and small companies.

    This article has been viewed 2,178 times.

    There are several ways to help you delete files read-only on Linux. If it’s a file you own, you can change the file permissions or use the sudo command to delete the original file. However, if you cannot delete the file with write permissions (or see the “Read Only File System” error message), you need to change the drive with the appropriate permissions. This article will show you how to delete read-only files on any Linux distribution, including Ubuntu and Linux Mint.

    Thank you for reading this post How to Delete Read-Only Files on Linux at Tnhelearning.edu.vn You can comment, see more related articles below and hope to help you with interesting information.

    Related Search:

    Related Posts

    How to Create Curved Text in Photoshop
    How to fall asleep faster
    How to Install FBReader to Read eBooks

    Category: How To

    Previous Post: « Top 10 beautiful and famous tourist destinations in Cat Ba – Hai Phong
    Next Post: Top 15 delicious steakhouses in Ho Chi Minh City you should try »

    Copyright © 2025 · Tnhelearning.edu.vn - Useful Knowledge