chmod

change access permissions of a file 

Command, KornShell Built-in


SYNOPSIS

chmod [-fR] mode pathname ...


DESCRIPTION

chmod changes the access permissions or modes of the specified files or directories. Modes determine who can read, change or execute a file.

Options

-f 

does not issue error messages concerning file access permissions, even if chmod encounters such errors.

-R 

changes the access permissions of all files and subdirectories under a directory if one is specified as a path name on the command line.

Modes

You can specify the mode value on the command line in either symbolic form or as an octal value.

A symbolic mode has the form

[who] op permission [op permission ...]

The who value is any combination of the following:

u 

sets user (individual) permissions.

g sets group permissions. o sets other permissions. a sets all permissions; this is the default.

On Windows file systems, there are no group or other permissions. Therefore, they always match the individual permissions.

The op part of a symbolic mode is an operator that tells chmod to turn the permissions on or off. The possible values are:

+ 

turns on a permission.

- turns off a permission. = turns on the specified permissions and turns off all others.

The permission part of a symbolic mode is any combination of the following:

r 

read permission. If this is off, you cannot read the file. The extended FAT and NTFS file systems ignore this permission since all files are always readable.

x 

Execute permission. If this is off, you cannot execute the file. The extended FAT and NTFS file systems ignore this permission since they consider all files executable.

X 

Execute/search permission for a directory; or execute permission for a file only when the current mode has at least one of the execute bits set. The extended FAT and NTFS file systems ignore this permission since they consider all files executable and all directories searchable.

w 

Write permission. If this is off, you cannot write to the file.

h 

Hidden attribute. Only the extended FAT and NTFS file systems recognize this attribute.

a 

Archive bit. Only the extended FAT and NTFS file systems recognize this attribute.

s 

On POSIX-compliant and UNIX systems, this stands for setuid on execution or setgid on execution permission. On Windows systems, this stands for a system file.

S 

On NTFS 5.0 (and up) file systems (available only on 8.1/2012R2/10/2016/2019/11/2022 system), this is the sparse file bit. Due to limitations in the file system, once you have set this attribute, you cannot turn it off without recreating the file.

t 

On UNIX systems, this stands for the sticky bit. On 8.1/2012R2/10/2016/2019/11/2022, it refers to the temporary file bit.

c 

Compressed file attribute.

You can specify multiple symbolic modes if you separate them with commas.

Absolute modes are octal numbers specifying the complete list of attributes for the files; you specify attributes by OR'ing together these bits.

01000000  temporary file
02000000  compressed file
04000000  sparse file
4000      Hidden file (setuid bit)
2000      System file (setgid bit)
1000      Archive bit (sticky bit)
0400      Individual read
0200      Individual write
0100      Individual execute (or list directory)
0040      Group read
0020      Group write
0010      Group execute
0004      Other read
0002      Other write
0001      Other execute

This list shows the first three bits with their meanings on Windows systems and with their meanings on UNIX and POSIX-compliant systems in parentheses. The MKS version of chmod tries to handle options in a way that parallels the POSIX approach. In the following list, each line shows a group of calls that are equivalent.

chmod 0000   chmod o=s
chmod 2000   chmod g=s   chmod =s
chmod 4000   chmod u=s   chmod =h
chmod 6000   chmod a=s   chmod ug=s   chmod =hs

Note:

=s is equivalent to 2000 on Windows systems; on UNIX and POSIX-compliant systems, =s is equivalent to 6000. MKS intends these equivalences to support commands ported to Windows from UNIX or POSIX-compliant systems. Such ported commands do not do the same thing that they do on UNIX or POSIX-compliant systems, (since Windows systems do not have the same file attributes as UNIX and POSIX), but the commands work in a consistent manner.

To get a read-only file on Windows systems, you must turn off all three write permission bits; if any of the three is on, Windows considers the file to be writable.

On Windows systems, the lc and ls commands both indicate the mode settings of files. The Windows dir command does not show these attributes, and the attrib command may only work with the read-only attribute, depending on the version of your operating system.


EXAMPLES

chmod -w nowrite

makes file nowrite read-only.

chmod +hrs sysfile

sets the hidden, read-only, and system attributes for sysfile.

chmod a=rwx file

turns on read, write, and execute permissions, and turns off the hidden, archive, and system attributes. This is equivalent to

chmod 0777 file

On 8.1/2012R2/10/2016/2019/11/2022, the command

chmod -R +c d:/

compresses the D: drive.


DIAGNOSTICS

Possible exit status values are:

0 

Successful completion.

1 

Failure due to any of the following:

— unable to access a specified file
— unable to change the modes on a specified file
— unable to read the directory containing item to change
— encountered a fatal error when using the -R option
2 

Failure due to any of the following:

— missing or invalid mode argument
— too few arguments

Messages

fatal error during "-R" option 

You specified the -R option but some file or directory in the directory structure was inaccessible. This may happen because of permissions or because you have removed a removable disk unit.

read directory "name

You do not have read permissions on the specified directory.


NOTE

chmod is provided as both an external utility and a built-in MKS KornShell utility.


PORTABILITY

POSIX.2. x/OPEN Portability Guide 4.0. Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.

Different systems interpret some mode bits in different ways.

The -f option as well as the a, c, h, and t permissions are extensions to the POSIX standard.


AVAILABILITY

PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Commands:
lc, ls, sh

Miscellaneous:
stat


PTC MKS Toolkit 10.4 Documentation Build 39.