This tutorial will guide you through the steps of how to make a file read. This is useful for all computers, but also comes in handy if your computer does not recognize some other programs as an executable and therefore can’t run them., or maybe it isn’t letting you save any files because that program ran into errors.
The “how to make a file read-only” is a question that has been asked many times before. This tutorial will help you understand what the options are when it comes to making a file read-only.
It’s time to make a file read-only in Windows if you want to be sure it doesn’t get modified under any circumstances. Setting a file to read-only or write-protecting it prohibits it from being changed in any way. You’ve come to the correct spot if you don’t know how to make files read-only but need to.
You’ll learn how to establish and delete the read-only attribute in File Explorer, the command line (cmd), and PowerShell in this video!
Let’s get this party started.
Prerequisites
This article will be a step-by-step guide. If you want to follow along, make sure you have the following items on hand:
- A computer that runs on Windows. Windows 10 and Windows PowerShell 5.1 will be used in this lesson.
- Toggle the read-only attribute on using this file. The file C:Sharedreadme.txt will be used in this lesson.
In File Explorer, how to make a file read-only (and writable)
There are a number different methods to make a file read-only, but let’s start with how to do it in Windows File Explorer.
Rather of being placed in the file’s content, the read-only attribute is saved as a metadata property. Windows File Explorer may be used to see the property.
Assuming you’re on your Windows PC’s desktop, perform the following:
1. Open Windows File Explorer and go to the folder containing the file you’ll be working with (in this case, C:Shared).
2. To access the file’s Properties box, right-click the file and choose Properties. This box provides information about the file, such as its size, creation and modification dates, and so on. It contains file characteristics as well.
To write-protect or set the file as read-only, select the read-only checkbox in the Attributes group, click Apply to assign the read-only attribute, then OK to dismiss the dialog box.
The readme.txt file’s properties box. Take note of where the Read-only attribute check box and the Apply button are located.
Uncheck the Read-only option to remove the read-only attribute from the file.
How to Use the Command Line to Make a File Read-Only (and Writable)
File characteristics aren’t just accessible via File Explorer. You may also use the command line to change file attributes, such as the read-only attribute. To do so, you’ll need to utilize the attrib command.
1. Open a command prompt on your computer (cmd.exe).
2. Go to the folder where the file is stored.
3. Execute attrib with no arguments. The attrib command will quickly search the working directory for all files and return all files together with their enabled file attributes. The read-only property is not enabled in the readme.txt file, as you can see below.
There is an archive attribute (A) but no read-only attribute (R)
4. To assign the read-only attribute, execute attrib. The +r option is crucial in this case. This argument instructs Windows to set the file’s read-only attribute.
5. Verify that the read-only attribute was applied by running attrib again without any arguments. The R label appears in the snapshot below, showing that the read-only attribute has been applied to write-protect the file.
The R (read-only) property is now enabled.
Similarly, the -r parameter can be used to remove the read-only attribute.
How to Use PowerShell to Make a File Read-Only (and Writable)
Look no further than PowerShell if you don’t like the GUI or the command prompt, or if you want a little more control. Let’s look at how to use PowerShell to make a file read-only.
- Open the Windows PowerShell command prompt.
2. Use the Get-Item cmdlet to provide the path of the file you want to make read-only. Each file attribute that is presently enabled is shown in the Attributes property.
format-table name, attributes | get-item -Path “c:sharedreadme.txt”
Only the Archive attribute is turned on.
It’s not required to use the Style-Table cmdlet, but it instructs PowerShell to show just the two attributes you’re interested in in an easy-to-read format (Name and Attributes)
Get-ChildItem: Listing Files, Registry, and Certificates is related to Get-ChildItem: Listing Files, Registry, and Certificates.
3. Add the ReadOnly attribute to the Attributes property, as shown below, to assign the read-only attribute.
$file = Get-Item -Path “c:sharedreadme.txt” ## Capture the file object in the $file variable. 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 to avoid overwriting the existing attributes. @($file.Attributes,”ReadOnly”) Attributes = @($file.Attributes,”ReadOnly”)
The Read Only Attribute Is Assigned
4. Now look at the Characteristics property of the $file object, and you’ll notice that you’ve added the ReadOnly attribute to the file while keeping any other attributes it had before. You may run Get-Item again if you want to get the same results.
Getting a Glimpse of the Attribute Property
Follow the same steps to remove the ReadOnly attribute from the file, but this time change the value of the Attributes property to Normal, e.g. $file. “Normal” is the attribute value.
Learning the Format-Table Cmdlet in PowerShell
Conclusion
You should now be able to read-only a file and vice versa. The purpose of making a file read-only is to avoid unintentional alterations. But keep in mind that making a file read-only isn’t inherently a security precaution; it doesn’t prevent someone from accessing the file or altering the attribute themselves.
Do you have any files you’d want to safeguard now that you’ve learned how to prevent files from being mistakenly overwritten?
To make a file read-only in Linux, you must use the “chmod” command. The “chmod” command takes two arguments: the first is the permission that you want to change and the second is the file name. You will also need to specify what type of access you want for this file. For example, if you wanted to make a file read only for everyone but give it write permissions to your user account, you would run “chmod ug=rwX filename”. Reference: how to make a file read-only in linux.
Related Tags
- how to make a file read-only in windows 10
- how to make a file read-only pdf
- how to make a file read only word
- how to make a file read only in java
- how to make a file read-only excel