---
title: "How to Make a File Read-Only and Vice Versa"
description: "Have you ever accidentally overwritten a file or folder? In this article, learn how to stop accidental data loss by learning how to make a file read-only."
canonical: "https://adamtheautomator.com/how-to-make-a-file-read-only/"
---

# How to Make a File Read-Only and Vice Versa

> Have you ever accidentally overwritten a file or folder? In this article, learn how to stop accidental data loss by learning how to make a file read-only.

Source: https://adamtheautomator.com/how-to-make-a-file-read-only/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Make a File Read-Only and Vice Versa](https://adamtheautomator.com/wp-content/uploads/2021/05/How-to-Make-a-File-Read-Only-and-Vice-Versa.jpg)

# How to Make a File Read-Only and Vice Versa

[![](https://secure.gravatar.com/avatar/94bb9f4917a5d829150fd33780938df32b516ee578009f07428971b8e3cb724c?s=192&d=mm&r=g)Jeff Stokes](https://adamtheautomator.com/author/jeff-stokes/)5 May 20213 min. read

Categories: [Home Ops](/category/home-ops/)

Tags:[File Properties](/tag/file-properties/)[Windows 10](/tag/windows-10/)

Table of Contents

*   [Prerequisites](#h-prerequisites)
*   [How to Make a File Read-Only (and Writable) in File Explorer](#h-how-to-make-a-file-read-only-and-writable-in-file-explorer)
*   [How to Make a File Read-Only (and Writable) via Command Line](#h-how-to-make-a-file-read-only-and-writable-via-command-line)
*   [How to Make a File Read-Only (and Writable) with PowerShell](#h-how-to-make-a-file-read-only-and-writable-with-powershell)
*   [Conclusion](#h-conclusion)

When you need to ensure a file isn’t changed under any circumstances in Windows, it’s time to make it read-only. Setting a file as read-only or write-protecting a file prevents any changes whatsoever. If you don’t know how to set files as read-only and need to, you’re in the right place!

In this tutorial, you’re going to learn how to set and remove the read-only attribute in File Explorer, the command-line (cmd), and via PowerShell!

Let’s get going.

## Prerequisites

This post will be a hands-on tutorial. If you’d like to follow along, be sure you have the following:

*   A Windows PC. This tutorial will use Windows 10 and Windows PowerShell v5.1.
*   A file to toggle the read-only attribute on. This tutorial will use a file located at _C:\\Shared\\readme.txt_.

## How to Make a File Read-Only (and Writable) in File Explorer

There are a few different ways to set a file as read-only but let’s start out this tutorial by first covering how to make it happen via Windows File Explorer.

> _The read-only attribute is stored as a metadata property rather than in the content of the file. The property can be seen through Windows File Explorer._

Assuming that you’re on the desktop of your Windows PC:

1\. Open Windows File Explorer and navigate to the folder that stores the file you’ll be working with (_C:\\Shared_) in this instance.

2\. Right click the file and click **Properties** to open the file’s **Properties** box. This box contains various metadata about that particular file such as size, when it was created, modified, etc. It also has file attributes.

Click the read-only checkbox in the **Attributes** group to write-protect the file or set it as read-only, click **Apply** to assign the read-only attribute, and **OK** to close the dialog box.

![The properties box of the file readme.txt. Note the location of the Read-only attribute check box and the Apply button.](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-11.png)

The properties box of the file readme.txt. Note the location of the Read-only attribute check box and the Apply button.

> _Similarly, to remove the read-only attribute from the file, uncheck the **Read-only** checkbox._

## How to Make a File Read-Only (and Writable) via Command Line

File attributes aren’t just exposed via File Explorer. You can also manipulate file attributes including the read-only attribute via the command line. To do so, you must use a command called [`attrib`](https://home.csulb.edu/~murdock/attrib.html#:~:text=Using%20the%20ATTRIB%20command%2C%20you,to%20as%20read%2Fwrite).

1\. Open up a command prompt (_cmd.exe_)_._

2\. Navigate to the folder the file is in.

```powershell
cd c:\shared
```

3\. Run `attrib` with no parameters. The `attrib` command will immediately look for all files in the working directory and return all files and the enabled file attributes. You can see below the _readme.txt_ file does not have the read-only attribute enabled.

![Archive attribute enabled (A) but no read-only attribute (R)](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-12.png)

Archive attribute enabled (A) but no read-only attribute (R)

4\. Now, run `attrib` to assign the read-only attribute. The `+r` parameter is key here. This parameter tells Windows to set the read-only attribute on the file.

```powershell
attrib +r readme.txt
```

5\. Run `attrib` again with no parameters to verify the read-only attribute was applied. You can now see in the screenshot below the `R` label shows up indicating the read-only attribute has been applied write-protecting the file.

![Read-only attribute (R) is now enabled ](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-13.png)

Read-only attribute (R) is now enabled

> _Similarly, to remove the read-only attribute use the `-r` parameter._

## How to Make a File Read-Only (and Writable) with PowerShell

If you’re not a fan of the GUI or the command prompt or want to use have a little more ease of control, look no further than PowerShell! Let’s now learn how to make a file read-only with PowerShell!

1.  Open Windows PowerShell.

2\. Run the `Get-Item` cmdlet providing the path to the file you’re toggling the read-only attribute on. The `Attributes` property returned contains each file attribute that’s currently enabled.

```powershell
get-item -Path "c:\shared\readme.txt" | format-table name, attributes
```

![The Archive attribute is only enabled. ](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-14.png)

The Archive attribute is only enabled.

> _Using the [`Format-Table`](https://adamtheautomator.com/powershell-format-table/) cmdlet is not necessary but by doing so, tells PowerShell to display only the two properties you’re interested in in an easy-to-view format (`Name` and `Attributes`)_

Related:[Get-ChildItem: Listing Files, Registry and Certificates](https://adamtheautomator.com/get-childitem/)

3\. Assign the read-only attribute by adding the `ReadOnly` attribute to the `Attributes` property as shown below.

```powershell
## Capture the file object in the $file variable
 $file = Get-Item -Path "c:\shared\readme.txt"
## Not to overwrite the existing attributes, create a new array containing
## the current file attributes while adding the ReadOnly attribute and assign
## that array as the new value of the Attributes property
 $file.Attributes = @($file.Attributes,"ReadOnly")
```

![Assigning the Read Only Attribute](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-15.png)

Assigning the Read Only Attribute

4\. Now, view the `Attributes` property of the `$file` object and you’ll see that you’ve now applied the `ReadOnly` attribute to the file while maintaining any existing attributes that existed on the file beforehand. You can also run `Get-Item` again to view the same results.

![How to make a file read-only (Viewing the Attribute Property)](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-16.png)

How to make a file read-only (Viewing the Attribute Property)

_To remove the `ReadOnly` attribute from the file, follow the exact same approach but this time set the value of the `Attributes` property to `Normal` e.g. `$file.Attributes = "Normal"`._

Related:[Learning PowerShell Format-Table Cmdlet](https://adamtheautomator.com/powershell-format-table/)

## Conclusion

You should now know how to set a file as read-only and vice versa. Setting a file as read-only is meant to prevent accidental changes. But know that, setting a file as read-only is not necessarily a security measure and does not prevent access to the file or someone from simply changing the attribute themselves.

Armed with this new knowledge of protecting files from being accidentally overwritten, do you have any files you’d like to protect?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fhow-to-make-a-file-read-only%2F&text=How%20to%20Make%20a%20File%20Read-Only%20and%20Vice%20Versa)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fhow-to-make-a-file-read-only%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fhow-to-make-a-file-read-only%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2021/10/How-to-Set-up-Pihole-in-a-Docker-Container.jpg)

### [How to Set up Pihole in a Docker Container](/pi-hole-in-docker/)

Annoying ads? Why not block them with Pi-hole in Docker container? Learn how to setup Pi-hole Docker container in this tutorial!

![](https://adamtheautomator.com/wp-content/uploads/2021/06/How-to-Fix-All-of-Those-Feature-update-to-Windows-10-Errors.jpg)

### [How to Fix All of Those “Feature update to Windows 10” Errors](/feature-update-to-windows-10/)

Keeping Windows 10 up to date is important but you might run into one of the infamous “feature update to Windows 10” errors. Learn how to fix it here.

![](https://adamtheautomator.com/wp-content/uploads/2021/03/9-Ways-to-Clean-Up-Windows-10-Step-by-Step.jpg)

### [9 Ways to Clean Up Windows 10 With Disk Cleanup Cmd](/disk-cleanup-cmd/)

Learn how to delete backup files in Windows 10, clean up temp files, Windows file history and more to keep Windows 10 clean.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
