Linux Text Processing Tools

Source: Internet
Author: User
Tags diff

Linux Text Processing Tools

Special permissions on 1.Linux file system: SUID SGID Sticky

Security context for a process: (1) Any executable program file can be started as a process, depending on whether the initiator has permission to execute the program file

(2) After initiating as a process, its owner is the initiator, the group is the group that the initiator belongs to

(3) Process access to files, depending on the initiator of the process

(a) initiator of the process, owner of the same document: The application file belongs to the master permission
(b) The initiator of the process, belonging to the group of documents; Apply file group permissions
(c) application file "other" permission

The suid is only valid for binary executable programs and is not set in the directory: chmod u+s file

SGID takes effect on a binary file, inherits the permissions of the group to which the program belongs chmod g+s

Role in the directory, the group of new files within the directory automatically inherit the directory belongs to the group (this is very useful)

Sticky sticky bit action in the directory, only the owner of the files in the directory can delete chmod o+t

when the privilege x is not executed, the special permission s,t becomes uppercase, and the special permission bits can be represented by a number 4,2,1, respectively U,g,o

To prevent users from misoperation, you can also create specific properties for a file:

Chattr +i file cannot be deleted, renamed, changed; -A indicates a lock timestamp,

Chattr +a can only append content

To view specific properties of a file: lasttr files

Acl:access control List for flexible rights management

In addition to the owner of the file, the owning group and others, you can set permissions on more users

ACL Effective Sequence: Owner, custom user, custom group, other user

Learn by example: support for using –r recursive settings

Setfacl-m u:wang:rwx filename|dir #自定义用户wang have rwx permissions for files

Setfacl-m g:group:rwx Filename|dir #自定义组group有文件的rwx权限

Setfacl-x U:username #从文件acl表删除用户

-K: # Clears the default ACL permissions and adds no emptying; completely empty using-B

Getfacl Filenam #查看文件的acl权限列表

Once you have ACL permissions, the permissions of the middle group are not the original meaning, but the mask limit high permission

Mask:r limit High Line means that the highest privilege is r and cannot exceed
Exam:setfacl-m Mask::rx File

The processing tools for text are: Less cat head tail cut grep sort Uniq Cat TAC Rev

CAT-E: Display line terminator $ head-n# specify get before # bytes taii-n#

-N: Number per line-# specify get before # line-#

-A: Show all controls-C # Specify the number of rows-c#

-S: Compresses consecutive empty lines into a row-F dynamically displays the appended content

cut-d:-f2 filename-d Specify delimiter:-f Specifies the segment to be extracted, you can specify multi-segment and continuous

Paste F1 F2 #合并两文件同行号的列到一行

Paste-s F1 F2 #也是合并意思, just F1 content line display, F2 content is also shown in a row, you can think of two lines of file

Wc-l-w-c #分别统计行数, number of words, number of bytes;

Sort-r #执行反方向 (top to bottom) finishing

-N #执行按数字大小整理

Uniq-c #显示每行重复出现的次数

-D #仅显示重复过的行

-U #仅显示不曾重复的行

Diff F1 F2 #比较两个文件之间的区别; the output of the command is saved in a file called "Patch"

Use the-u option to output the "unified (Unified)" diff format file, which is best for patch files.

Patch-b #适用-B option to automatically back up changed files; Diff and Patch are meant to be patched.

Text Processing Three Musketeers

grep: Text Filtering tool grep, Egrep, fgrep (regular expression not supported)

sed : Stream editor

awk : Implementation gawk on Linux, Text Report Generator

grep [OPTIONS] PATTERN [FILE ...] Patterns: Filter conditions written by regular expression characters and text characters

-V #显示不被模式匹配到的行-I #忽略字符大小写

-N #显示匹配的行号-C #统计匹配的行号

-O #仅显示匹配到的字符串-Q #静默模式, output nothing

-a-b-C # display mode matches to the previous, upper and lower # lines, corresponding to the word meaning After,befor,context

-e #实现多个选项间的逻辑or Relationship-e #使用扩展正则表达式-F #使用fgerp

Regular expression: A pattern written by a class of special characters and text characters, where some characters (metacharacters) do not represent literal meanings, but are functions of control or wildcard

Divided into two categories: basic Regular Expression: BRE extended Regular expression: ERE

And the file name is a bit different, not the same as the individual

. #匹配任意单个字符

* #匹配前面的字符任意次, greedy mode: match as long as possible

. * #任意长度的任意字符

\{m,n\} #匹配前面的字符至少m次, up to N times

^ Beginning anchor $ line end anchor ^$ empty line

\b Word anchor for the left \ba of the word pattern #a在词首

\b Ending anchoring; right a\b for Word mode #a在词尾

\<pattern\> # matches the entire word \ is escaped

Group: \ (\) Bind one or more characters together and treat them as a whole, such as: \ (root\) \+

Back reference: References the pattern in the preceding grouping brackets matches the character, not the pattern itself

To extend the regular expression:

* #匹配前面字符任意次

? #0次或1次

+ #一次多多次

{m,n} #至少m次, up to n times, can also be separated

C|cat:c or Cat (c|c) At:cat or cat

Linux Text Processing Tools

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.