• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Linux Chmod Command

Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Razvan Ludosanu

Founder, learnbackend.dev

Updated: 7/2/2024

Published: 12/14/2022

About Terminus

The short answer

On Unix-like operating systems, such as Linux and macOS, the chmod command is used to change the read, write, and execute permissions of files and directories.

$ chmod <permissions> <file …>

Run in Warp

Where:

  • permissions is a list of permissions in the octal or symbolic notation.
  • file … is a list of paths to the files or directories you want to change the permissions of.

The meaning of permissions for files and directories

Permissions for files and directories have a slightly different meaning.

Permissions for files

The read permission means that the specified user can open and view the contents of a file, but cannot modify or delete it.

The write permission means that the specified user can modify the contents of a file or delete it.

The execute permission means that if the file contains executable code, such as a shell script or a compiled binary, the specified user can run it as a program.

Permissions for directories

The read permission means that the specified user can list the contents of a directory, but cannot create, delete, or modify files within it.

The write permission means that the specified user can create, rename, delete, or modify files within the directory.

The execute permission, combined with the read permission, means that the specified user can enter the directory.

The octal notation

The octal notation is a numeric representation of file permissions in the form of a 3-digit number, where each digit (from left to right) represents the permissions for the owner, the group, and the others (e.g., 755).

In this notation, each individual permission is assigned a numeric value where:

  • 4 represents the read permission.
  • 2 represents the write permission.
  • 1 represents the execute permission.
  • 0 represents the absence of permission.

And then added up to create an individual permission set.

For example:

$ chmod 740 script.sh

Run in Warp

This command will give:

  • Read, write, and execute permissions (i.e., 4 + 2 + 1) to the owner of the file.
  • Read permission (i.e. 4) to the group.
  • No permissions (i.e. 0) to the others.

The symbolic notation

The symbolic notation is a text representation of file permissions in the form of 3 sets of 3 letters, where each set (from left to right) represents the permissions for the owner, the group, and the others (e.g., rwxr-xr---).

In this notation, each individual permission is assigned a letter where:

  • r represents the read permission.
  • w represents the write permission.
  • x represents the execute permission.
  • - represents the absence of permission.

And then chained together to create a permission set.

To change the permissions of a file using the symbolic notation, you can use the following syntax:

$ chmod <who><operator><permissions><file …>

Run in Warp

Where:

  • who represents who you want to change permissions for, where u stands for owner, g for group, o for others, and a for all.
  • operator indicates the operation to perform, where + is used to add permissions, - to remove permissions, and = to set exact permissions.
  • permissions specifies the permissions to add, remove, or set.

For example:

$ chmod u=rwx,g+x,o-wx script.sh

Run in Warp

This command will:

  • Set read, write, and execute permissions to the owner of the file.
  • Add execute permission to the group.
  • Remove write and execute permissions to the others.

Easily retrieve this command using Warp’s AI Command Suggestions

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Entering add read and write permissions for the owner in the AI Command Suggestions will prompt a chmod command that can then be quickly inserted in your shell by doing CMD+ENTER .

Using chmodwithsudo

The sudo command is used to execute a command as the superuser (or root).

Executing the chmod command with sudo allows you to modify the permissions of a file or directory that you do not have access to as the current user.

$ sudo chmod <permissions> <file …>

Run in Warp

Note that if you don't have access to the sudo command on your system, you'll need to contact the system administrator to modify your access to any files you lack permissions for.

The -h flag tells chmod that if the file is a symbolic link, change the permissions on the link itself, rather than the file it points to.

The -R flag tells chmod to act recursively, which is generally advised against, as covered in how to run chmod recursively.

Note that the -R flag can be combined with the -H flag to prevent chmod from following symlinks or with the -L flag to force chmod to follow all symlinks.

Written by

Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Razvan Ludosanu

Founder, learnbackend.dev

Filed Under

Related Articles

List Open Ports in Linux

Learn how to output the list of open TCP and UDP ports in Linux, as well as their IP addresses and ports using the netstat command.

UnixLinux
Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Count Files in Linux

Learn how to count files and folders contained in directories and subdirectories in Linux using the ls, find, and wc commands.

LinuxUnix
Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

How to Check the Size of Folders in Linux

Learn how to output the size of directories and subdirectories in a human-readable format in Linux and macOS using the du command.

LinuxUnix
Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

POST JSON Data With Curl

How to send valid HTTP POST requests with JSON data payloads using the curl command and how to avoid common syntax pitfalls. Also, how to solve the HTTP 405 error code.

BashUnixLinux
Thumbnail for Neeran GulThumbnail for Neeran GulThumbnail for Neeran GulThumbnail for Neeran Gul
Neeran Gul

Format Command Output In Linux

Learn how to filter and format the content of files and the output of commands in Linux using the awk command.

Linux

Create Groups In Linux

Learn how to manually and automatically create and list groups in Linux.

Linux

Switch Users In Linux

Learn how to switch between users, log in as another user, and execute commands as another user in Linux.

Linux

Remover Users in Linux

Learn how to remove local and remote user accounts and associated groups and files in Linux using the userdel and deluser commands.

Linux

Delete Files In Linux

Learn how to selectively delete files in Linux based on patterns and properties using the rm command.

Linux

Find Files In Linux

Learn how to find and filter files in Linux by owner, size, date, type and content using the find command.

Linux

Copy Files In Linux

Learn how to safely and recursively copy one or more files locally and remotely in Linux using the cp and scp command.

Linux

Create Files In Linux

Learn how to create regular files in Linux using command line interface commands like touch, echo, cat, printf, and in-terminal text editors like Vim.

Linux

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for nullThumbnail for nullThumbnail for nullThumbnail for null