What about Linux file permissions?

Source: Internet
Author: User
Linux is a multi-user, multi-task operating system. its attributes for each file include: file owner, file group, and other users ), you must also have the read, write, and execute permissions corresponding to these three roles. for example, there is... linux is a multi-user, multi-task operating system. its attributes for each file include: file owner, file group, and other users ), you must also have the read, write, and execute permissions corresponding to these three roles, such:

There is an a.txt file under the tmpdirectory. we can use the ls-l command to view its details:-: indicates a common file, d: indicates a directory file, l: link file, B: interface devices that can be stored in device files. c: Serial port devices in device files, such as keyboards. Because the header is-: a.txt is a common file. Let's look at the rw-r -- section. we divide it into three groups, corresponding to the file owner, the file owner group, and permissions of other users. r indicates the read permission, w: indicates the write permission, x: indicates the execution permission (not shown here), and-: indicates that you do not have a certain permission. The preceding permission is interpreted as: www.2cto.com owner: can read and write, cannot execute group: can read, cannot write, cannot execute other: can read, cannot write, the first root cannot be executed to represent the file owner, and the second root cannot represent the file owner group. now, if I want to modify the file owner, the file owner group, and the file permission, please continue to read down: chgrp: modify the group to which the user belongs. chown: modify the file owner. chmod: modify the file permission. suppose another group named gavin is in my system (view it through/etc/group)

For example, use the chgrp command to change the group of the file to the owner of the file under gavin:
Modify its permissions:
Chmod 777 a.txt what does this 777 mean? In linux, use numbers to indicate permissions: r: 4 w: 2 x: 1 www.2cto.com r -- = 4 + 0 + 0 = 4; rw-= 4 + 2 + 0 = 6; rwx = 4 + 2 + 1 = 7 I believe everyone should understand it here. Permissions have different meanings for files and folders. for files: r: indicates that files can be read, w: indicates that files can be modified, x: you can execute this file for the folder: r: to get the files in the folder, w: to add and delete the content in the folder, x: to enter the folder, if a role has the rw-permission on a folder, it can only use ls to get the content in the folder, but cannot use cd to enter the folder. File permissions come to an end. now let's take a look at the common directories in linux: The/bin system has many directories for storing execution files, but/bin is special, because/bin is placed with commands that can be operated in single-user maintenance mode, the commands under/bin can be used by root and general accounts, such as cat, chmod, chown, data, mv, mkdir, cp, bash, and other common commands. /Boot is mainly used to place the file www.2cto.com/dev used for power-on. in linux, any device or interface device is stored in this directory as a file, accessing a file is equivalent to accessing the main configuration files of the device/etc system in this folder class. /Home this is the default Main user folder/Library of the lib system, 2. lib is the function library/mnt available. if you want to temporarily mount it on some external devices (CDS), we recommend that you store it in this directory. /Opt: this is the directory for third-party software/master folder of the root system administrator/tmp. this is the place where files are placed by common users or programs being executed, this directory can be accessed by anyone, so you need to clear it regularly. of course, important data cannot be put here. The last point about the file permission is: the default file permission umask now we know how to create or change the attributes of a directory, but you know that when you create a new file or the directory is, what is its default permission? This is because umask is related. what is umask? basically, umask is the default value for permissions when users create files or directories, if you obtain or set umask, the method is as follows: # umask or umask-S www.2cto.com

(Four-digit, no matter the first one, it indicates special permissions. we can start from the second.) on the default permissions, files and directories are different. for a directory, the x permission is very important. for a file, the x permission should not be available by default. because most files are used to store data, in linux, the default permission of the file is 666, and the default permission of the directory is 777. Note that the umask score indicates the "default permission to be deleted", so the permission for creating a new file: rw -- r -- new directory: r-xr-x from java tutorial network

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.