Linux file management and text one of the Three Musketeers grep, and the use of regular

Source: Internet
Author: User
Tags expression engine egrep

1: File Permissions

There are three types of user access to a file: R (Read), W (write), X. It's a little different for files and directories.

File:

R: Use the text View tool to view its file contents.

W: Use the text Editing tool to edit its file contents.

X: You can request this file to run as a city execution to the kernel.

Directory:

R: You can use the LS command to list files under Subdirectories and files.

W: You can create and delete files in this directory.

X: You can use the ' ls-l ' command to list the file attributes of the directory and subdirectories, and you can use the CD to switch the working directory to a directory.


File permissions are primarily defined for three types of objects.

Owner: Master, group: Genus, Other: other users.

Three commands for Rights management

Change file belongs to group: CHGRP Group name File name

If the file test belongs to the test group change to the Admin group, the command is: CHGRP admin test.

-r: Represents a cascade change to the owning group of sub-files and subdirectories in this directory.


Document owner management: Chown

If the file test belongs to test, it is the main CentOS chown CentOS test.

-R: Also represents a cascading change.

The owning and owning group of the Cascade change file

Chown-r user name: The owning group file name.


Change the file's ownership limit Chmod:r=4,w=2,x=1

chmod [-r] XYZ file permissions.

The first type of change:

If you change the Cascade change file, test is the master for read-write only execute permissions, the group is read permission, and the other is the EXECUTE permission. Chmod-r u=wrx,g=wr,o=x Test

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/91/wKioL1XnBMvQTlE8AADt5XBBCq4526.jpg "title=" @WV ' Sjp3yjj_$8hj0u{nn7m.png "alt=" Wkiol1xnbmvqtle8aadt5xbbcq4526.jpg "/>


Second change: You can use +WRX, or-WRX +: to indicate an increase in permissions, which means to remove the permissions you have.

Chmod-r U-WR,G+X,O+WR Test

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/91/wKioL1XnBj7hG3vbAAEmAuEWtbA273.jpg "title=") BR) _v0eozm9knc ' 9lene.png "alt=" Wkiol1xnbj7hg3vbaaemauewtba273.jpg "/>


Third change: 7=wrx r=4,w=2,r=1 with digital permissions 0 means no permissions.

Chmod-r 701 Test

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/95/wKiom1XnBSeQ0uVuAAD--xejx0s458.jpg "title=" 440R) Q7%yiakvrgvxs7c177.png "alt=" Wkiom1xnbseq0uvuaad--xejx0s458.jpg "/>


The default permission for a directory is 755, and the permission for a file is 644

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/91/wKioL1XnCI2w6zZQAAINGZzUiZc603.jpg "title=" {qt5[ 9q{(to[ne$af5innb8.png "alt=" Wkiol1xnci2w6zzqaaingzzuizc603.jpg "/>

The default permissions for a file depend on the Umask value

Umask: Represents the default value of the current user's permissions when creating a new file or directory.

Enter the default permission value that the Umask command is currently losing.

By default, the rule

1: The default maximum permission of 666 is U=WR,G=WR,O=WR when creating a file. One less enforcement privilege is due to security considerations and the file start-up cannot be executed.

2: When creating a directory, the directory has execute permissions because it is going to the directory, so the maximum permissions for the directory are 777.


Defines a umask value of 002

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/92/wKioL1XnEIfDGglOAABdmWIIASs124.jpg "title="]y ( ISAVWLO8$8}MH) b_$aab.png "alt=" Wkiol1xneifdggloaabdmwiiass124.jpg "/>


Because the Umask 002 value is defined. Because the highest permission to create a file is 666, the default initial permissions are:

U, is the main WR-0=WR representative has read and write permission, G belongs to the group wr-0 =WR Read and Write permissions, the other user and group permissions for Rw-w=r only Read permissions, this is the creation of files.

When creating a directory, because the most permission to create the directory is 777, so the owner: Wrx-0=wrx owns WRX, the group WRX-0=WRX has the WRX,O=RWX-X=RW has the RX permission.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/92/wKioL1XnEobz_HD-AACt6cgrkOU930.jpg "title=" Z$FG ( xkm[$U 8~m%8s$rksml.png "alt=" Wkiol1xneobz_hd-aact6cgrkou930.jpg "/>


If the value of Umask is 003 then for the creation of the file is the main RW, belong to the group RW other user rw-w=r value.

If the value of Umask is 005 then the file carcass is the main RW, which belongs to the group RW, and the other user rw-r=w. Because there is no execution permission by default, you must remove the Execute permission. For example 003 The last 3 of the theoretical authority for WX, because there is no execution permissions so the actual permission is W, minus the W so R, so the end of the other user and group permissions for the R permission.


2: Text One of the Three Musketeers use of grep


The Three Musketeers of Linux text Processing.

grep: Text Filtering tool.

Sed: text editor.

awk: Text Report Generator.



Grep:global search REgular expression and print out of the line based on the global regular representation of the matching-to-row printing tool.

Pattern: The filter condition written by the metacharacters of the regular expression and the text characters.

Metacharacters: A character does not represent its literal meaning, but is used to denote a wildcard or control function.

The regular is divided into two categories:

Basic Regular Expressions: BRE

Extended Regular expression: ERE

grep [option] PATTERN file:

--color: The matching to the string to do highlighting;

-V: Displays the rows that the pattern does not match.

-I: Ignore case.

-O: Displays only the strings that can be matched to;

-Q: Silent mode.



The grep family has three commands:

grep: basic Regular expression

-e: Extended expression support

-F: Regular expressions are not supported.

Egrep: Extended Expression

Fgrep: Regular expressions are not supported.


The metacharacters of the basic regular expression:

Character Matching:

.: matches any single character.

[]: Match a single character within the established range, such as [0-9] representing any character within 0-9, [a_z] table uppercase any single character within a-Z, [A-z]: Express lowercase letters of any single character.

[^]: Set the non-single character within the range.

Common Special Symbols:

[: Lower:]: represents lowercase characters [a-z]

[: Upper:]: Represents uppercase characters [A-z]

[: Space:]: Represents a blank key.

Number of occurrences that specify the number of occurrences of the preceding character

*: Only occurrences of the preceding character are repeated any time.

\? : 0 or 1 times. \ represents escape.

\+:1 times or more.

\{m\}: Represents the exact m-time.

\{n,m\}: Represents [N,m] interval times.

\{0,n\}: Up to n times.

\{m,\}: At least m times.

. *: Matches any character of any length.


Location anchoring:

^: Anchor at the beginning of the line.

$: End of line anchoring.

\<,\b: The word header is anchored to the left side of the pattern that represents the word;

\>,\b: The ending anchor is used to represent the right side of the word pattern.

^$: Blank line.

Grouping \ (\)

The content that is matched in the grouping parentheses is recorded by the regular expression engine during execution and saved to the variable. These variables are \1,\2 ...


Back reference: Use a variable to refer to the character to which the pattern in the preceding grouping brackets matches.

Expansion Regular Expression

or expression: | A|b

C|cat: Indicates C or cat, not cat or cat, to write (C|c) at

+: Repeat one or more of the previous regular re

? : 0 or one of the previous characters.

(): Find the group character

() +: Determination of multiple repeating groups.

1. Display the lines in the/etc/passwd file that end with bash

grep ' bash$ '/etc/passwd

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/93/wKioL1XnKBDCWy-FAADVIQ4i-nw626.jpg "title=" V ' Dv465ebhrztfqx1tt{6gb.png "alt=" Wkiol1xnkbdcwy-faadviq4i-nw626.jpg "/>

2. Display the two-digit or three-digit number in the/etc/passwd file

grep ' [0-9]\{2,3\} '/etc/passwd

3. Display lines with ' LISTEN ' followed by 0, one or more whitespace characters in the ' Netstat-tan ' command result

?

4. Add user bash, Testbash, basher, and Nologin user (Nologin user's shell is/sbin/nologin), then find the same line in the/etc/passwd file as the user name and its shell name

?

5. Display the default shell and UID of root, CentOS, or User1 user on the current system (please create these users beforehand, if not present)

?

6, find a word in the/etc/rc.d/init.d/functions file (the middle of the word can be underlined) followed by a set of parentheses line

?

7, use echo to output a path, and then egrep find its path base name; Further use Egrep to remove its directory name

?

8. Find the number between 1-255 in the result of ifconfig command execution

?










Linux file management and text one of the Three Musketeers grep, and the use of regular

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.