The mode
of a new file is set based on the umask
--reference=reffile chmod [Options]… symbolic-mode file …
use
chmod [Options]…
m m m
file …
reffile
's mode
-R |
Symbolic-Mode options:
[ugoa
[+-=
][rwx Xst
]
ugoa
specifies which users' access to the file will be changed:
a ll user's flags (which are not inhibited by umask).
|
|
|
rwxXst
select the modes for the specified users:
r
ead , w
rite, ex
ecute
eX
ecute only if the file is a directory or already has execute permission for some user
s
et user or group ID on execution†
t
Save program t
ext on swap device ( perhaps a performance enhancer )
For a directory mode means: read:list files, write:add, execute:access
Examples
chmod a-w file
chmod a+r file
chmod g+rw file
chmod =rx,g+s file
first digit | special attributes usually not used |
| ||||||
second digit | owner |
| ||||||
third digit | group |
| ||||||
fourth digit | other users NOT in the file's group |
|
The mode
is calculated by adding the values.
User (owner) (rwx) = 400+200+100= 700 ; Group(rx) = 40+10 = 50; Other (x) = 1 results in:
mode = 751
Setting mode to 777 should be avoided as this permits anyone to modify the file.
chmod 750 file
ls -l file
-rwxr-x--- 1 dgerman team2 978 22 May 19:10 file
chmod 760 file
ls -l file
-rwxrw---- 1 dgerman team2 978 22 May 19:10 file
For symbolic links: the mode is not changed since they are not used.
The mode of the target file is changed except during recursive directory traversals.
This page documents the GNU version of chmod.
see also:
ls -l
lists current permissions for --
u (owner) rwx -- g (group) rwx -- O (Other) rwx --
chgrp - Change group ownership
chown - Change file owner and group
umask - sets "allowed" filter
Windows equivalent commands:
ATTRIB - Change file attributes
CACLS - Change AccessControlList settings
XCACLS - Change file permissions
Fat file system only supports readonly, hidden, sys
and archive
. see
ATTRIB.exe
ATTRIB [ +| attribute ] [pathname] [/S [/D]] [/L]
Display or change file attributes.
+ : Turn an attribute ON - : Clear an attribute OFF
pathname |
/S |
The numeric values can be used when changing attributes with VBS/WSH If no attribute is specified attrib will return the current attribute settings. Used with just the /S option ATTRIB will quickly search for a particular filename. In older versions of Windows, Explorer would display 'p' to indicate a 'sparse' file.
Hidden and System attributes take priority. If a file has both the Hidden and System attributes set, you can clear both attributes only with a single ATTRIB command.
For example, to clear the Hidden and System attributes for the RECORD.TXT file, type: ATTRIB -S -H RECORD.TXT
If a file has the System or Hidden attribute set, you must clear that attribute before you can change any other attributes with ATTRIB. Wildcards You can use wildcards (? and *) with the pathname parameter to display or change the attributes for a group of files.
Directory Attributes You can display or change some attributes for a directory/folder.
The Read-only attribute (R) does not apply to a folder. This is because a unlike a file, a folder object does not contain any content that can be edited. The Name of a folder can be changed but that is a rename operation not an edit of the contents.
The Read-only attribute of a folder can be set or cleared in Windows Explorer as a fast method of setting/clearing the Read-only attribute of all files within the folder. It does not actually set the attribute on the folder itself.
To use ATTRIB with a directory, you must explicitly specify the directory name; you cannot use wildcards to work with directories. So the following command would affect only files, not directories: ATTRIB +H C:*.*
To hide the directory C:\SECRET: ATTRIB +H C:\SECRET
Detect whether a path points to a file or a directory by reading the Extended Attribute for 'Directory' (as listed below).
The System attribute is used by Windows to determine that a folder is a special folder, such as My Documents, Favorites, Fonts, etc.
Archive attribute The Archive attribute (A) is used to mark files that have changed since they were previously backed up. The (A) flag is automatically updated by Windows as the file is saved. If the (A) flag is present - the file is new or has been changed since the last backup. The MSBACKUP, RESTORE, and XCOPY commands use these Archive attributes, as do most 3rd party backup solutions.
Temporary attribute DFSR will not replicate files if they have the Temporary attribute set. The temporary attribute can be removed by using PowerShell to subtract 0x100: PS C:\> Get-childitem D:\Data -recurse | ForEach-Object -process {if (($_.attributes -band 0x100) -eq 0x100) {$_.attributes = ($_.attributes -band 0xFEFF)}}
Extended Attributes are only available on NTFS volumes. File attributes can be read with FSUTIL usn readdata filename.ext Constants - the following attribute values are returned by the GetFileAttributes function:
(R) Read-only file. |
CACLS - Change file permissions. An alternative way to display extended attributes is using FOR parameter attributes FSUTIL - File and Volume utilities. Show superhidden file extensions. Q326549 - Read-only & System attributes for folders. PowerShell equivalent:(Get-Item 'example.txt').Attributes / Get-ItemProperty / Set-ItemProperty - Example script Equivalent bash command (Linux): chmod - Change access permissions.