😎
CS1.dev
  • Welcome to Computer Science 1
  • Unit 2
    • Activity 2.1
    • Activity 2.2
    • Activity 2.3
    • Activity 2.4
    • Activity 2.5
    • Activity 2.6
    • Activity 2.7
    • Activity 2.9
    • Activity 2.10
    • Project 2
    • Activity 2.8
    • Activity 2.11
    • Activity 2.12
    • Activity 2.13
    • Activity 2.14
    • Activity 2.15
    • Activity 2.16
    • Activity 2.17
    • Activity 2.18
    • Activity 2.19
    • Project 3
    • Activity 2.20
    • Activity 2.21
    • Activity 2.22
    • Activity 2.23
    • Activity 2.24
    • Project 4
    • Activity 2.25
    • Activity 2.26
    • Activity 2.27
    • Activity 2.28
    • Project 5
    • Activity 2.29
    • Activity 2.30
    • Activity 2.31
    • Activity 2.32
    • Activity 2.33
    • Activity 2.34
    • Activity 2.35
    • Activity 2.36
  • Unit 3
    • Activity 3.1
    • Activity 3.2
    • Activity 3.3
    • Activity 3.4
    • Activity 3.5
    • Activity 3.6
    • Activity 3.7
    • Activity 3.8
    • Activity 3.9
    • Activity 3.10
    • Activity 3.11
    • Project 6
    • Activity 3.12
  • Activity 3.13
  • Activity 3.14
  • Activity 3.15
  • Activity 3.16
  • Project 7
  • Activity 3.17
  • Activity 3.18
  • Activity 3.19
  • Project 8
  • Linux
    • bash
    • cat
    • cd
    • chmod
    • df
    • echo
    • find
    • grep
    • less
    • ls
    • mkdir
    • more
    • pwd
    • tar
    • touch
    • unzip
    • zip
Powered by GitBook
On this page
  1. Linux

chmod

The chmod command in Linux is a crucial tool used for changing the file permissions of files and directories. The name chmod stands for "change mode", and it allows users to set or modify the read, write, and execute permissions for the owner, group, and others on a file or directory. Understanding how chmod works is fundamental for managing access control in Linux. Here are the key aspects of the chmod command:

  1. File Permissions: In Linux, each file and directory has three types of permissions:

    • Read (r): Permission to view the contents of the file or directory.

    • Write (w): Permission to modify the contents of the file or directory.

    • Execute (x): Permission to execute the file or access the directory.

  2. Permission Groups: Permissions are set for three different groups:

    • Owner (u): The user who owns the file.

    • Group (g): The group that is assigned to the file.

    • Others (o): Everyone else who is not the owner or part of the group.

  3. Numeric (Octal) Mode: chmod can be used with numeric codes to set permissions. These codes are:

    • 4 for read (r)

    • 2 for write (w)

    • 1 for execute (x)

    • These values are added together to set multiple permissions. For example, 6 (4+2) means read and write.

    To set permissions for owner, group, and others, you combine these numbers. For example, chmod 755 filename sets the permissions to read/write/execute for the owner (7), and read/execute for the group and others (5 and 5).

  4. Symbolic Mode: chmod can also be used with symbolic notation, which uses letters and symbols to represent permissions:

    • u, g, o for owner, group, and others

    • + to add a permission

    • - to remove a permission

    • = to set a permission and unset others

    • For example, chmod g+w filename adds write permission for the group.

  5. Recursive Option: To change permissions for a directory and all its contents, use the -R (recursive) option, like chmod -R 755 directoryname.

  6. Security Context: Correctly setting file permissions is important for system security. Overly permissive settings can expose files to unwanted modifications or access.

  7. Special Modes: Besides the basic permissions, chmod can also set special modes such as the setuid, setgid, and sticky bit. These are advanced features used for specific purposes in the file system.

PreviouscdNextdf

Last updated 1 year ago