Linux Commands-chmod: changing file mode

Source: Internet
Author: User

The mode of the file

When you use the LS-L command to view directory content

[Email protected] cmdline]$ ls-l/etc/passwd-rw-r--r-- 1 root root 1917 Jul  2 15:01/etc/passwd

The first column field is the file mode. The first character represents the file type, where "-" indicates that the file is a normal file. The following 9 characters represent access to the file, divided into Read permissions, write permissions, and execute permissions, respectively, for three objects: owner, same group of users, and other users. Here "-rw-r--r--" means that the owner of the file has read and write permissions, while the same group of users and other users are only used for Read permissions.

Types of files
Property File type
- Normal file
D Catalog files
L Symbolic Links
C Character device files. The file type represents a device, such as a terminal or modem, that processes data in the form of a byte stream.
B Block device files. This file type represents a device that handles data in chunks, such as a hard drive or a disc drive.
Permission Properties
Property File Directory
R Allows you to open and read files. Allows you to list content under a directory.
W Allows you to write or truncate files, but this permission does not allow you to rename or delete files. The ability to rename and delete files is determined by directory permissions. If execute permission is also set, the files in the directory are allowed to be created, deleted, and renamed.
X Allow the file to execute as a program. A program written in a scripting language must be set to be readable so that it can be executed. Allow access to the directory, such as CD directory.

Octal digit notation
octal Binary file Mode
0 000 ---
1 001 --x
2 010 -w-
3 011 -wx
4 100 r--
5 101 R-x
6 110 rw-
7 111 Rwx
Notation notation
symbols Meaning
U The user's abbreviation, which represents the owner of the file or directory
G A group abbreviation that indicates the group to which the file belongs
O othes abbreviation, which means all other users
A The abbreviation for all, is the combination of u, G and O three

If no characters are specified, all is assumed to be used. The operator "+" means adding a permission, "-" means deleting a permission, "=" means that only the specified permission is available and all other permissions are removed.

Command format

chmod [OPTION] ... MODE [,MODE] ... FILE...
chmod [OPTION] ... Octal-mode FILE...
chmod [OPTION] ...--reference=rfile FILE...

Command parameters

-C,--changes
Similar to the-v option, but only displays diagnostic information if the file mode changes.

--preserve-root
Recursive operation of the root directory is forbidden.

-F,--silent,--quiet
Remove most of the error messages.

-V,--verbose
The diagnostic information is displayed when each file is processed.

--reference=rfile
Use the mode of the Rfile file rather than specifying the permission mode yourself.

-R,--recursive
Changes the mode of files and directories recursively.

--help
Displays help information.

--version
Displays version information.

Instance

A) Change the hello.sh mode to 744 (rwxr--r--).

[[email protected] cmdline]$ ls-l hello.sh-rw-rw-r--1 ucm ucm 0 Oct  chmod 744 hello.sh [[email protected] cmdline]$ ls-l hello.sh-rwxr--r-- 1 ucm UCM 0 Oct  3 17:00 hello.sh

b) Add executable permissions for the user of the group to which hello.sh belongs.

[[email protected] cmdline]$ ls-l hello.sh-rwxr--r--1 ucm ucm 0 Oct  chmod g+x hello.sh [[email protected] cmdline]$ ls-l hello.sh-rwxr-xr--1 ucm UCM 0 Oct  3 17:00 hello.sh

c) Remove other users ' Read permissions to the hello.sh.

[[email protected] cmdline]$ ls-l hello.sh-rwxr-xr--1 ucm ucm 0 Oct  chmod o-r hello.sh [[email protected] cmdline]$ ls-l hello.sh-rwxr-x---1 ucm UCM 0 Oct  3 17:00 hello.sh

d) Set the hello.sh owner permission to rw-, remove the executable permissions of the owning group user, and add read permissions to other users.

[[email protected] cmdline]$ ls-l hello.sh-rwxr-x---1 ucm ucm 0 Oct  chmod u=rw,g-x,o+r hello.sh [[Email PR Otected] cmdline]$ ls-l hello.sh-rw-r--r-- 1 ucm UCM 0 Oct  3 17:00 hello.sh

Linux Commands-chmod: changing file mode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.