chmod Command in Linux with Examples

Posted in

chmod Command in Linux with Examples
sangeeta.gulia

Sangeeta Gulia
Last updated on April 26, 2024

    Access modes of files and directories is a helpful feature that restricts the users to allow only specified operations on the files. A file can be accessed with different modes by different users. The chmod command in Linux helps us to set the access modes of files and directories. In this article, we will discuss various options and examples of the chmod command.

    chmod Command in Linux

    The chmod command is used to modify the access mode of a file in Unix-like and Linux operating systems. Change mode is abbreviated in the name. The syntax is:

    chmod [reference][operator][mode] file... 

    Options and Examples of chmod command

    +rwx : This is used to add permissions on files and directories

    -rwx : This is used to remove permissions from files and directories.

    +x : This is used to set executable permissions.

    -wxr : This is used to remove write, read, and executable permissions.

    —version

    This option is used to display information about the version of the command

    -c, —changes

    This option is identical to verbose, except it reports whether or not a change has been made.

    -f, —silent, —quiet

    It is used to silence or suppress the error messages and warnings.

    -v, —verbose

    This option displays a diagnostic for each file that is handled.

    —no-preserve-root

    This option prevents the backslash sign ('/') from being treated (the default).

    —preserve-root

    If this option is used, the recursive operation on backslash ('/') will fail.

    —reference=RFILE

    It specifies the RFILE's mode instead of the MODE settings.

    -R, —recursive

    This option is used to recursively alter files and directories.

    —help

    This option displays the help manual, which includes a brief overview of how to use this command and its options.

    Mapping permissions to numeric digits

    0: ---

    1: --x

    2: -w-

    3: -wx

    4: r-

    5: r-x

    6: rw-

    7: rwx

    Conclusion

    In this article, we went through the chmod command in Linux, which is used to change the access modes of the files. It provides options like recursive alteration of files, displays diagnostic for files, notify the change, etc.

    People are also reading:

    Leave a Comment on this Post

    0 Comments