chmod Command - Change Permissions

You can change the permissions using the chmod command .

chmod Permission FileName

Some representations of permissions allow you to add permissions by delta, such as octal and "+ x".

This is a sample to change permissions.

# Specify in octal
chmod 644 foo.txt
chmod 755 dir1

# Add execute permission
chmod +x myapp

Recursively change permissions

There is a "-R" option to change permissions recursively.

There is "-R", but the permissions you want to set for directories, normal files, and executable files are different, so if you change them all at once, it will be difficult.

You may also want to give execute permission only to a specific extension.

In such a case, combine the find command, the grep command, and the xargs command. Let's narrow down to the target file and change the permissions.

For example, if you want to give execute permission only to the ".pl" file under the current directory, do as follows.

find * | grep -P '\.pl$' | xargs chmod +x

Associated Information