Linux text editing commands

Source: Internet
Author: User
Tags diff

  • The cut command is used to display the specified part of the row, deleting the specified field in the file. Cut is often used to display the contents of a file, similar to the following type command

    #其中, if you want to specify multiple columns in the Cut command,-F1 can be written as-f1,3,7 (Comma separated)

    Cut-c display only the contents of a specified field
    Cut-d the delimiter for the specified field
    Cut-b displays only the contents of the direct range specified in the row

      • The umask command is used to set the mask that restricts new file permissions. Permissions are determined by the mask when the new file is created. Each time the user registers into the system, the Umask command is executed and the mask mode is automatically set to restrict the permissions of the new file. The user can change the default value by executing the umask command again, and the new permission will overwrite the old.
          umask 022

    Setting the mask to 022, the default permission to create a new file is 777-022 for 755
    namely *rwxr-xr-x
    Umask values are stored in/ETC/BASHRC, used by all user settings, and stored in ~/.BASHRC only for a user setting

      • ACL permissions (access control list) are access-controlled lists. Mainly for a single user, a single file or directory for the rwx permissions of the details set. Can be set for user, Group (group), default property Mask (umask).
        The process of opening ACLs on new partitions in CENTOS6
        1. Create a partition
        Fdisk/dev/sda
        N Enter
        Enter
        +2G Enter
        W Enter
        2. Synchronizing Partitioned Tables
        Partx-a/DEV/SDA
        3. Creating a File system
        Mkfs.ext4/dev/sda6
        4. Turn on ACL support
        Tune2fs-o Acl/dev/sda6
        5. View ACLs
        Tune2fs-l/dev/sda6 |grep option

        Getfacl filename/directory

    View ACL properties for files/directories

            setfacl命令是用来在命令行里设置ACL(访问控制列表)。        在命令行里,一系列的命令跟随以一系列的文件名。

    -B,--Remove-all: Remove all extended ACL rules, basic ACL rules (owners, groups, others) will be retained.
    -K,--Remove-default: Removes the default ACL rule. If there is no default rule, you will not be prompted.
    -n,--no-mask: Do not recalculate effective permissions. Setfacl ACL mask is recalculated by default unless mask is explicitly formulated.
    --mask: Recalculates effective permissions, even if ACL mask is explicitly specified.
    -d,--default: Sets the default ACL rule.
    --restore=file: ACL rules for recovering backups from files (these files can be generated by getfacl-r). This mechanism allows you to recover ACL rules for the entire directory tree. This parameter cannot be executed in conjunction with any parameters other than--test.
    --test: The test mode does not change the ACL rules for any files, the ACL specification after operation will be listed.
    -r,--recursive: Recursively operates on all files and directories.
    -l,--logical: Trace Symbolic Link, by default only the symbolic link file is tracked and the symbolic link directory is skipped.
    -p,--physical: Skips all symbolic links, including symbolic link files.
    --version: Outputs the version number of the Setfacl and exits.
    --HELP: Output help information.
    --: Identifies the end of the command line argument, and all subsequent parameters will be considered file names
    -: If the file name is--Setfacl will read the file name from the standard input.

        setfacl用法()


    Clear default Permissions

    Setfacl-k file

    Clear ACL Properties

    Setfacl-b file

                acl权限的备份及还原                            getfacl file |directory > acl.txt                            setfacl --restore acl.txt
      • Sort

                -n 按数字排列        -r 倒序排列,默认升序        -t 指定分隔符        -k 指定哪一列        -f 忽略大小写        -u 删除重复行
      • Uniq

                去除连续重复行,往往和sort配合使用,先排序,再去重        -c 显示重复的次数        -d 仅显示重复行        -u 仅显示非重复行
      • Diff

                diff f1 f2 比较两个文件的不同之处        diff -u f1 f2 > diff.log        (此命令可以生成补丁文件,可以用patch打补丁)
      • Grep

                    --color=auto 关键字高亮显示            -v 反向搜索            -i 忽略大小写            -n 显示行号

                    -c 不显示搜索结果,仅显示匹配的行数                -o 仅显示匹配到的字符串                -q 静默输出                -A #  显示搜索行及其向下相临的#行                -B #  显示搜索行及其向上相临的#行                -C #  显示搜索行及其向上和向下相临的#行                -e char1 -e char2 [-e charN] 多个选项间or关系                -w 匹配整个单词                -E 或egrep 支持扩展正则表达式                -F 或fgrep 不支持正则表达式
    • Vim is a very powerful text editor, with a wide range of skills and efficiency
      When the vim filename is executed, if the file exists, the file is opened directly, and if the file does not exist, a file named filename is opened at the same time, and the "new file" is prompted at the bottom left
      If you open a file that already exists, you will be prompted at the bottom left.

          Three main mode command modes (default): Move cursor, copy, cut, paste, undo, Redo, search, go to other modes move cursor: H move Left                    L Move J down move K up move mate #h, #l, #j, #k可一次性移动 # Characters                    W jumps to the next word first B jumps to the last word first H jumps to the top of the current page m jumps to the current page L jump to the current footer GG jumps to the entire file of the first line G jumps to the end of the entire file ^ moves to the beginning of a non-whitespace $ shift                    To the end of the line #G跳到指定行, or exit mode: # ctrl+f: Flip a screen to the tail of the file ctrl+b: Flip a screen to the file header                    Ctrl+d: Half-screen to the end of the file Ctrl+u: replace one character D cut to the first half screen r of the file DD cut the current line #dd剪切 # line DW cut a word d^ from the cursor to the beginning d$ or D from the cursor                    Cut to end of line y copy yy or y Copy the current line #yy复制 # line yw copy a word  y^ Copy from the cursor to the beginning of the row                  y$ Copy from the cursor to the end of the line p paste p The current line is pasted down or the cursor is positioned back paste p The current line is pasted up or the cursor is located                     Paste forward Replace mode R enter ESC exit from command mode into insert mode I cursor where to enter I the cursor moves to the beginning of the line and into the insertion mode                    A cursor moves backward one character at a time into insert mode a cursor moves to the end of the line while entering insert mode o cursor inserts a new row and enters insert mode                    o Insert a new row into insert mode: Text edit exit Mode: Save, Exit W: Save Q: Exit                    q! Force exit Wq or X save and exit w! if the current user is a member of the file, if the file is read only, you can add! Force save. Returns the command mode in exit mode ESCESC or enter R/path/filename reads the contents of another file and writes the output to a file W/path/fi Lename Save As (verify that the current user has WX permissions on the last level in the path)! command executes an order to display the output on the terminal r! Command executes one of the commands, inserts a new row down the current line where the cursor is located, and enters the output. Command executes one of the commands, replaces the current line where the cursor is located and enters the output

    Linux text editing commands

    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.