Linux study Notes-file permission management

Source: Internet
Author: User
Tags sorted by name
Linux Study Notes & mdash; file permission management abstract: sort out file permission management and take notes before using Linux-file permission management

Abstract: sort out the file permission management and add the commands that may be used before use. if you do not want to pay too much attention, you can directly view the following sections about permissions, including modifying file permissions. modify the user and user group of the file.

I. Significance of specific file attributes 1. Command: ls

Ls command format: ls [option] [directory name].

Ls command: list all subdirectories and files in the target directory.

Common ls commands:

-A,-all: list all files in the directory, including hidden files starting.

-A is the same as-a, but does not list "." (indicating the current directory) and "." (indicating the parent directory of the current directory ).

-C combination-lt: ctime-based sorting and ctime-based display (time when the last File state is changed) combination-l: ctime is displayed, but ctime is sorted by name. otherwise: ctime-based sorting

-C. list projects from top to bottom in each column

-Color [= WHEN]: determines whether to use color to distinguish files. WHEN can be either 'Never ', 'Always', or 'auto '.

-D,-directory displays the directory like a file, instead of the file under it.

-D and-dired generate results suitable for the dired mode of Emacs

-F does not sort the output files. the-aU option takes effect and the-lst option is invalid.

-G is similar to-l, but the owner is not listed.

-G,-no-group does not list any information about the group.

-H,-human-readable list the file size in an easy-to-understand format (for example, 1 K 234 M 2G)

-Si is similar to-h, but the file size is equal to the power of 1000 instead of 1024.

-H,-dereference-command-line use the symbolic link in the command column to indicate the real destination

-Indicator-style = specifies that the indicator is added after each project name. <方式> : None (default), classify (-F), file-type (-p)

-I,-inode: print the inode number of each file

-I,-ignore = the style does not print any shell-compliant universal characters <样式> Project

-K is-block-size = 1 K, which indicates the file size in the form of k bytes.

-L in addition to the file name, the file permission, owner, file size, and other information are listed in detail.

-L,-dereference: when the file information of the symbolic link is displayed, the object indicated by the symbolic link is displayed, not the information of the symbolic link itself.

-M all items are separated by commas (,) and the whole row width is filled.

-O is similar to-l, and displays details of files except group information.

-R,-reverse in reverse order

-R,-recursive lists all sub-directory layers at the same time

-S and-size are used to list the size of all objects in the unit of block size.

-S sort by file size

-Sort = Below is an optional WORD and the corresponding options they represent:

Extension-Xstatus-c

None-U time-t

Size-S atime-u

Time-t access-u

Version-v use-u

-T sort by file modification time

-U with-lt: Display access time and sort by access time

Combined with-l: Display the access time, but sort by name

Otherwise: Sort by access time

-U is not sorted; items are listed in the original order of the file system.

-V sort by version

-W,-width = COLS: specify the screen width without using the current value.

-X: list projects row by row instead of column.

-X sort by extension

-1. only one file is listed in each row.

-Help: displays the help information and leaves.

-Version: displays the version information and leaves.

2. file attributes

A) file attributes

The file attributes have been described in detail in the previous notes. here is a brief introduction:

You can run the ls-l command to view a directory and obtain a list of nine fields.

Information displayed in row 3: total usage (total)-This value is the sum of the 1st fields in all files and directories in the Directory (in k ), that is, the directory size.

Field 1st:

File attribute field

The file attribute field consists of 10 letters. The first letter indicates the file type. if the letter is a minus sign (-), it indicates that the file is a common file. the letter "d" indicates that the file is a directory, the letter "d", is the abbreviation of dirtectory (directory. note that a directory or folder is a special file, which stores information about other files and folders.

Field 2nd

Number of hard links or subdirectories of files

Field 3rd:

File owner

Field 4th:

Group of the file owner

Field 5th:

File size (in bytes)

Field 6th:

File creation month

Field 7th:

File creation date

Field 8th:

File creation time

Field 9th:

File name (if it is a symbolic link, there will be a "->" arrow symbol, followed by a file to which it points)

B) numbers corresponding to file permissions:

I often see three numbers behind chmod and how do these numbers come from? Why can I modify the file permission in this way?

In fact, the reading, writing, and execution of files can all be expressed in an octal number:

R 100 -- 4 w 010 -- 2x001 -- 1

The result of adding these three octal numbers indicates the specific permissions of the group. for example:

7 = 4 + 2 + 1 = rwx

5 = 4 + 1 = rx

755 = 4 + 2 + 1 4 + 1 4 + 1 = rwx r-x

C) another permission implementation method

If we want to give a file the permissions we specify, or remove some permissions, such as my love letter is not visible to others, but we do not know whether the file itself has this permission, we can use it now. the following permission modification method:

A all users

U owner user

G owner group

O other users

= Permission

+ Add permissions

-Remove permissions

R read permission

W write permission

X executable permissions

The three columns in the table above can be combined to achieve the desired effect, for example:

A + x adds executable permissions to all users

Go-wx removes the writeable and executable permissions of the owner group and other users.

U = rwx: The owner has the readable, writable, and executable permissions.

II. file permission management 1. brief description of file operation commands:

Mkdir directory name => create a directory

Rmdir empty directory name => delete an empty directory

Rm file name => delete one or more files

Rm-rf non-empty directory name => delete everything in a non-empty directory

Touch file name => create an empty file

Rename a file (folder)/move a file (folder) to a specified folder

Execution format: mvsource destination

Example:

Mv file1 file2 => change file1 to file2.

Mv file1 dir1 => move the file file1 to the directory dir1, and the file name is still file1.

Mv dir1 dir2 => If the directory dir2 exists, move the directory dir1 and all its files and subdirectories to the directory dir2 with the new directory name dir1. If the directory dir2 does not exist, change dir1 and all its files and subdirectories to the directory dir2.

2. modify the file permission command -- chmod:

A) command format: chmod [-cfvR] [-- help] [-- version] mode file

B) command function: used to change the access permission of a file or directory and use it to control the access permission of a file or directory.

C) common command parameters:

-C report processing information when a change occurs

-F the error message is not output.

-R processes the specified directory and all files in its subdirectories.

-V displays detailed processing information during running

D) exp:

 

I) it is best to enter/tmp for safety. Ii) create a folder dir1 and modify the permission of this folder to 755 (for specific file permissions, refer to the above mkdir dir1 chmod755 dir1. you can use ls-l to view the attributes of the file or folder after each step.. Iii) create a multi-tier folder and modify the attributes of all folders to 777 mkdir-p dl_1/dl_2/dl_3 chmod-R dl_1 iv) I don't want any user to have writable and executable permissions on any files in dl_1. chmo-R a-wx dl_1/v) I want to make all files under dl_1 owned by my user group and me have the x file chmo-R ug + x dl_1/vi) I think my user group and I have the read and Operation permissions for dl_1 only. chmod-R ug = rx dl_1/
3. modify the file ownership-chown

A) command format: chown [option]... [owner] [: [group] file...

B) command function: use chown to change the owner and group of a file. When changing the file owner or group, you can use the user name and user ID settings. Normal users cannot change their files to other owners. The operation permission is generally administrator.

C) command parameters:

Required parameters:

-C: Display the changed information.

-F ignore error messages

-H: Fixed the symbolic link.

-R processes the specified directory and all files in its subdirectories.

-V: displays detailed processing information.

-Deference acts on the point of the symbolic link, rather than the link file itself.

Select parameters:

-- Reference = <目录或文件> Use the specified directory/file as a reference, and set the operated file/directory to the same owner and Group of the reference file/directory.

-- From = <当前用户:当前群组> Only when the current user and group are the same as the specified user and group

-- Help: displays help information.

-- Version: displays version information.

D) exp:

I) modify the dl_1 file to belong to test_user_2 user chowntest_user_2 dl_1/ii) modify the dl_1 file to belong to test_user_2 user and to test_group_1 user group chowntest_user_2: test_group_1 dl_1/iii) modify all files in dl_1 to test_user_2 user chown-R test_user_2 dl_1/iv) modify all files in dl_1 to test_user_2 user and to test_group_1 user group chown-Rtest_user_2: test_group_1 dl_1/
4. modify the file User Group-chgrp

A) command format: chgrp [option] [group] [file]

B) command function: the chgrp command can change the group of a file or directory by group name or group ID. The permission is a Super User.

C) command parameters:

Required parameters:

-C output debugging information when a change occurs

-F: no error message is displayed.

-R processes the specified directory and all files in its subdirectories.

-V displays detailed processing information during running.

-- Dereference acts on the direction of the symbolic link, rather than the symbolic link itself

-- No-dereference acts on the symbolic link itself

Select parameters:

-- Reference = <文件或者目录>

-- Help: displays help information.

-- Version: displays version information.

D) exp:

I) modify the user group to which the dl_1 file belongs

                     chgrp test_group_1 dl_1

Ii) modify the owner user group of all files in dl_1

                     chgrp –R test_group_1 dl_1
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.