attrib command in Windows
There is a command–line tool available in Windows Operating Systems, called the attrib.exe command tool. The attrib.exe command tool in Windows Operating Systems allows users to display or change the file or folder attributes. Before continuing, please visit the next link to know more about file attributes in Windows NFTS file system.
General syntax of the attrib.exe command–line tool is as below.
PS C:\jajish>attrib.exe [{+|-}r] [{+|-}a] [{+|-}s] [{+|-}h] [{+|-}o] [{+|-}i] [{+|-}x] [{+|-}p] [{+|-}u] [:][ ][ ] [/s [/d] [/l]]
Following table explains the attrib.exe command and how to set and remove file attributes in Windows NFTS file system using attrib.exe command tool.
File System Task | Character | attrib.exe command syntax | attrib.exe command example |
---|---|---|---|
Set Read–only attribute | +r | attrib.exe +r <file-name> | attrib.exe +r C:\jajish\test-file.txt |
Remove Read–only attribute | -r | attrib.exe -r <file-name> | attrib.exe -r C:\jajish\test-file.txt |
Set Archive attribute | +a | attrib.exe +a <file-name> | attrib.exe +a C:\jajish\test-file.txt |
Remove Archive attribute | -a | attrib.exe -a <file-name> | attrib.exe -a C:\jajish\test-file.txt |
Set System attribute | +s | attrib.exe +s <file-name> | attrib.exe +s C:\jajish\test-file.txt |
Remove System attribute | -s | attrib.exe -s <file-name> | attrib.exe -s C:\jajish\test-file.txt |
Set Hidden attribute | +h | attrib.exe +h <file-name> | attrib.exe +h C:\jajish\test-file.txt |
Remove Hidden attribute | -h | attrib.exe -h <file-name> | attrib.exe -h C:\jajish\test-file.txt |
Set Offline attribute | +o | attrib.exe +o <file-name> | attrib.exe +o C:\jajish\test-file.txt |
Remove Offline attribute | -o | attrib.exe -o <file-name> | attrib.exe -o C:\jajish\test-file.txt |
Set Not Content Indexed attribute | +i | attrib.exe +i <file-name> | attrib.exe +i C:\jajish\test-file.txt |
Remove Not Content Indexed attribute | -i | attrib.exe -i <file-name> | attrib.exe -i C:\jajish\test-file.txt |
Set No Scrub attribute | +x | attrib.exe +x <file-name> | attrib.exe +x C:\jajish\test-file.txt |
Remove No Scrub attribute | -x | attrib.exe -x <file-name> | attrib.exe -x C:\jajish\test-file.txt |
Set Pinned attribute | +p | attrib.exe +p <file-name> | attrib.exe +p C:\jajish\test-file.txt |
Remove Pinned attribute | -p | attrib.exe -p <file-name> | attrib.exe -p C:\jajish\test-file.txt |
Set Unpinned attribute | +u | attrib.exe +u <file-name> | attrib.exe +u C:\jajish\test-file.txt |
Remove Unpinned attribute | -u | attrib.exe -u <file-name> | attrib.exe -u C:\jajish\test-file.txt |
Examples of attrib.exe command
Set Hidden attribute for a folder and its contents recursively
PS C:\jajish> attrib +h C:\jajish\*.* /d /S
Remove Hidden attribute for a folder and its contents recursively
PS C:\jajish> attrib -h C:\jajish\*.* /d /S
Display the attributes of a file named test-file.txt inside the current folder
PS C:\jajish> attrib.exe .\test-file.txt A R C:\jajish\test-file.txt
Note that ".\" in the above attrib.exe command example is used to specify the current directory in the command–line. Similarly you can also use "../" to specify the parent directory in the command–line.
Display the attributes of all files under a folder
PS C:\jajish> attrib.exe C:\jajish\drivers\point64\* R C:\jajish\drivers\point64\point64.cat R C:\jajish\drivers\point64\point64.inf R C:\jajish\drivers\point64\point64.sys R C:\jajish\drivers\point64\wdfcoinstaller01011.dll
Above example lists the attributes of all files under the folder "C:\jajish\drivers\point64\". The wildcard * in above attrib.exe example is used to specify all the files under the folder "C:\jajish\drivers\point64\".
Set multiple attributes for a file
PS C:\jajish> attrib.exe +h +r .\test-file.txt
Remove multiple attributes from a file
PS C:\jajish> attrib.exe -h -r .\test-file.txt
Written by Jajish Thomas.
Last updated on 18th July, 2024.