Vim editor, find command and bash environment configuration

Source: Internet
Author: User
Tags define local glob line editor

1, summarize the text editing tool vim use method;

Full-screen editor: VIM

Vi:visual interface

Sed: line Editor

VI, VI improved

Vim:

Pattern:

Edit mode: Command mode

Input mode:

Last-line mode:

Edit mode--Input mode:

I:insert,

A:append,

O:new Line,

I: The beginning of the line

A: End of line

O: Above New CCB

Input mode--edit mode:

Esc

Edit mode--and last-line mode:

:

Last-line mode--edit mode

Esc

Open VIM:

# VIM

# Vim/path/to/somefile

+#: #为行号;

+/pattern

Turn off VIM:

: Q

: q!

: Wq

: X

ZZ: Save exit

Cursor Jump:

Jump between characters:

H:

L

J:

K:

#COMMAND:

Jump between words:

W: The first word of the word

E: The ending of the current or subsequent word;

B: The first word of the current or previous word;

#COMMAND:

In-line jump:

^: jumps to the first non-whitespace character at the beginning of a line;

0: Jump to the beginning of the line;

$: Jump to end of line;

Move between rows:

#G:

1G, GG

G

Move between sentences:

)

(

Move between paragraphs:

}

{

Edit command:

Character editing:

X: Delete the character at the cursor location

#x:

Xp:

R: replaces the character at which the cursor is located;

Delete command:

D:

d^

d$

D0

DW, DE, DB

Dd:

#COMMAND

Note: The deleted content will be saved to the buffer by the Vim editor;

Paste: P (paste, put)

If this copied or deleted content is not a full line

P: Paste at the back of the current cursor;

P: Paste at the front of the current cursor;

If the copied content is a full row (more than one line)

P: Paste below the line where the current cursor is located;

P: Above line;

Copy command: Y, yank

Y

y$, y^, y0

Ye, yw, yb

YY: Copying rows

#COMMAND

Changing the command: C, change

C $, c^, C0

CB, CE, CW

Cc:

#COMMAND

To undo a previous edit operation:

U:undo

Undo the previous edit operation;

#u

Ctrl+r:

Redo the previous undo operation

.: Repeats the previous edit operation

Turn screen operation:

Ctrl+f: one screen backward;

Ctrl+b: one screen ahead;

Ctrl+d: Back half screen

Ctrl+u: Forward half screen

Vim built-in tutorials:

Vimtutor

Vim's last-line mode

(1) Address, delimitation

: Start_pos,end_pos

#: Line #;

#,#

#,+#

.: When moving forward

$: Last line

%: Full text, equivalent to 1,$

/PAT1/: The first time the line is matched to this pattern;

#,/pat1/

/pat1/,/pat2/

After you can follow the edit command:

D, y

W, R

(2) Find

/pattern: to the tail

? PATTERN: To the header

N: Same direction as command

N: Opposite direction of command

(3) Find and replace

S: In the last line mode, the search and replace operation is done within the bounds of the address;

s/what to look for/replace with content/modifiers

What to look for: Available modes

What to replace: You cannot use a pattern, but you can use a back reference symbol to refer to what the grouping brackets in the preceding pattern match to;

\1, \2, ...

&: Refers to the entire content of the "What to find" matches;

Modifier:

I: Ignore case

G: Global Substitution

/: Used for delimiters, so, to find the content or replace with the content that appears in this symbol, to use \ to escape it, use format: \/

The delimiter can be replaced with other characters: @, #等, for example;

Multi-file Mode:

Vim FILE1 FILE2 ...

: Next

: First

:p Rev

: Last

: Wqall

: Q!all

Multi-File Window segmentation:

Vim-o|-o FILE1 FILE2 ...

Ctrl+w, ARROW

Single File Window segmentation:

Ctrl+w, S:split, horizontal split

Ctrl+w, v:vertical, vertical split

Some of the working features of the custom vim:

(1) Line number

Display: Set Nu

Disabled: Set Nonu

(2) Bracket matching

Display: Set SM

Disabled: Set NOSM

(3) Auto indent:

Set AI

Set Noai

(4) Highlight Search

Set Hlsearch

Set Nohlsearch

(5) Syntax coloring

Syntax on

Syntax off

(6) Ignore character case

Set IC

Set Noic

: Help for assistance

: Help SUBJECT

The permanent effect of the feature setting is as follows:

Global configuration file:/ETC/VIMRC

User profile: ~/.VIMRC

2, summarize the document Search command find use method;

Find command:

Find [OPTION] ... [Find Path] [Search Criteria] [Handling Action]

Find path: Default to the current path;

Search criteria: The specified search criteria, can be based on the file name, size, genus of the main group, type, etc., by default to find all the files under the specified path;

Handling actions: What to do with the eligible files; By default, output to the screen;

Search criteria:

To find by file name:

-name "file name": Supports the use of glob;

*, ?, []

-iname "file name": Character case insensitive, supports use of glob;

-regex "pattern": matches the entire file path string with pattern, not just the file name;

According to the genus, the genus Group looks for:

-user USERNAME: Find files belonging to the owner of the specified user;

-group GROUPNAME:

-uid UserID: A file that finds the owner-specified UID of a file;

-gid GroupID:

-nouser: Find files that are not owned by the master;

-nogroup: Find files without a group;

To find by file type:

-type type

F: Normal file

D: Catalogue

L: Symbolic Link

B: Block device

C: Character device

P: Named Pipes

S: Socket

Combination Lookup criteria:

and Conditions:-A

or condition:-O

Non-conditional:-not,!

! A-o! B =! (A-a B)

! A-a! B =! (A-o B)

Depending on the file size, look for:

-size [+|-] #UNIT

Unit: K, M, G

#UNIT: (#-1,#]

+ #UNIT: (#,+oo)

-#UNIT: [0,#-1]

Based on time stamp:

In "Days" as the unit

-atime [+|-]#

#:[#,#+1)

+#: [#+1,oo]

-#: [0,#]

-mtime

-ctime

In "Minutes" units

-amin

-mmin

-cmin

Based on permissions:

-perm [/|-]mode

MODE: Exact permission match

/mode: Any one of a class of objects (U,g,o) is eligible for any of the rights, implied or conditional;

/400

-mode: Every permission specified for each class of object must be in accordance with the condition;

Handling actions:

-print: Default handling action

-ls: Similar to the "ls-l" operation for each file found;

-delete: Delete the found file;

-fls/path/to/somefile: The detailed path information of the found file is saved to the specified file;

-ok COMMAND {} \;

The user must be confirmed beforehand before executing the specified command for each file;

-exec COMMAND {} \;

No user confirmation required;

3, summarize the content of bash environment variable;

Bash Environment configuration:

configuration file, the scope of effective, there are two categories:

Global configuration:

/etc/profile,/etc/profile.d/*.sh

/etc/bashrc

Personal configuration:

~/.bash_profile

~/.bashrc

By function, there are two categories:

Profile class: Provides configuration for the interactive logon shell

/etc/profile,/etc/profile.d/*.sh

~/.bash_profile

Function:

(1) Define environment variables, such as path, PS1

(2) run a command or script

BASHRC class: Provides configuration for non-interactive logon shell

/etc/bashrc

~/.bashrc

Function:

(1) Define command aliases;

(2) define local variables;

Variables: Memory space, variable name

Type:

Environment variables: scope current shell process and its child processes

Local variable: scope current shell process

Local variables: scoped only to a snippet of code in the current shell process (usually a function context)

Position variable: $ $, $

Special variables: $?

How variables are defined:

Bash built-in variables: can be called directly, built in a number of environment variables, such as Path

Custom variables:

Variable assignment: variable name = value

Bash Weak type:

When a variable stores data, it is written by default, and any variable can be directly referenced without being declared;

120:24bits

120:8bits

To define a local variable:

Name=value

View: Set

Define Environment variables:

Export Name=value

Declare-x Name=value

View: env, printenv, export

Undo Variable:

unset name

Reference variable:

${name}, $name

Reference symbols in bash:

': Strong reference, variable substitution does not occur

"": Weak reference

": Command Reference

Shell Logon Type:

Interactive login:

Login directly through the terminal;

User Switching implemented by su-l username command;

Non-interactive logon:

A command-line window opens under the graphical interface;

Execute the script;

Su Username;

Configuration file Action Order:

Interactive login:

/etc/profile--/etc/profile.d/*.sh--and ~/.bash_profile--~/.BASHRC--/ETC/BASHRC

Non-interactive logon:

~/.BASHRC--/ETC/BASHRC-/etc/profile.d/*.sh

How does the new configuration of the Edit profile definition take effect?

(1) Re-login;

(2) Let the current shell process to re-read the specified configuration file;

Source/path/to/somefile

. /path/to/somefile

4. Summarize the knowledge points of special permissions (SUID, SGID, Sticky) on Linux file system;

Special permissions on the Linux file system

Permission model:

U, G, O

R, W, X

Security context for the process:

Prerequisite: The process is owned by the owner (the process is running as the user's identity);

(1) Whether the user can start an executable program file as a process, depending on whether the user has Execute permission on the program file;

(2) After the program is started as a process, the owner of the process is the current user, the initiator of the process, the group to which the process belongs, and the base group for the initiator;

(3) The access rights of the process, depending on the owner's access rights:

(a) The owner of the process and the owner of the document, the application document is the master authority;

(b) The owner of the process, belonging to the group of documents, the application file is a group of permissions;

(c) Apply other rights;

SUID:

(1) Any executable program file can be started as a process: depending on whether the initiator has EXECUTE permission on the program file;

(2) After initiating as a process, its owner is not the initiator, and the program file is the owner of its own, the mechanism is suid;

Permission settings:

chmod u+s FILE ...

chmod u-s FILE ...

Attention:

S: The owner of the original X permission;

S: The original owner has no x permission;

SGID:

By default, when a user creates a file, it belongs to the base group that the user is a member of;

Once a directory has been set with Sgid permissions, the user who has write permission to this directory has the same group as the directory, not the user's base group, to which the files created in this directory belong.

Permission settings:

chmod g+s FILE ...

chmod g-s FILE ...

Sticky:

For a multi-person writable directory, this permission is used to restrict each file that can only delete itself;

Permission settings

chmod o+t FILE ...

chmod o-t FILE ...

5, summarize the Linux Disk Management, file system related knowledge points and the use of related commands;

Linux Disk Management

Hard disk:

Mechanical hard-disk

Ssds

Mechanical type:

Track

Sector:512bytes

Cylinder: The basic unit of the partition;

Mbr:master Boot Record

512bytes

446:bootloader

64:filesystem Allocation table

16: Identify a partition

2:55aa

Disk interface type:

IDE (ATA): 133MB/S,/DEV/HD

scsi:640mb/s

sata:6gbps

sas:6gbps

usb:480mb/s

Identify the hard drive device:/DEV/SD

Mark a different hard drive device:/dev/sd[a-z]

Mark different partitions on the same device:/dev/sd[a-z][1-]

1-4: Primary or extended partition identification

5 +: Logical partition identification

Device Files: Special files

Device number:

Major, minor

Major: Device type

Minor: Different devices under the same type

"Block": block, Random device

"Character": Character, linear device

Gpt

Partitioning: Separates the storage space into multiple small spaces, each of which can use the file system independently;

Partitioning tools:

Fdisk, parted, Sfdisk

Use of the Fdisk tool:

Support for up to 15 partitions on one hard drive;

Partition Management sub-command:

P: Display

N: Create

D: Delete

T: Modify the partition ID

L: List all support ID types

W: Save exit

Q: Discard Changes and exit

M: Get Help

After the creation is complete, check to see if the kernel has identified the new partition:

# cat/proc/partitions

There are three commands that allow the kernel to reread the disk partition table:

CentOS 5:partprobe [DEVICE]

CentOS 6, 7:

Partx

Kpartx

PARTX command:

Partx DEVICE

Partx-a DEVICE

Partx-a-N m:n DEVICE

M

M:

: N

KPARTX command:

Kpartx-af DEVICE

Linux File System Management

File system:

Vfs:virtual File System

Linux:ext2, Ext3, Ext4, ReiserFS, XFS, Btrfs, swap

Disc: iso9660

Windows:fat32 (VFAT), NTFS

Unix:ffs, UFS, JFS, JFS2

Network File System: NFS, CIFS

Cluster file system: OCFS2, GFS2

Distributed File systems: Ceph,

Moosefs, MogileFS, HDFs, GFS, Glusterfs

(1) journaled file system

Non-journaled file system: ext2

journaled File System: ext3

(2) Swap: Swap partition

To create a file system:

Perform formatting on a partition (advanced formatting)

To use a file system, two conditions are met:

Kernel: Support for this file system

User space: There are file System management tools

Create tool: Mkfs (make filesystem)

MKFS-T type DEVICE

Mkfs.type DEVICE

Special management tools for the EXT series file system:

mke2fs-t {EXT2|EXT3|EXT4} DEVICE

-B block:1024, 2048, 4096

-L ' LABEL ': Set volume label

Blkid command:

Blkid DEVICE

LABEL, UUID, TYPE

The Vim editor exercises :

1. Copy the/etc/grub2.cfg configuration file to the/tmp directory, remove the white space character from the beginning of the/tmp/grub2.cfg file with the find replacement command; (CentOS6:/etc/grub.conf)

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/AC/wKiom1Xq8j_yx0U2AAE-W9JvDQs725.jpg "/>

2. Copy the/etc/rc.d/init.d/functions file to the/tmp directory, and add a # to the beginning of the line beginning with a blank character for each line of/tmp/functions with the find replacement command; The original whitespace character is reserved;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/AC/wKiom1Xq8kCwZC9_AAHbqXwSVxo366.jpg "/>

3, replace the/etc/sysconfig/init in/tmp/functions file is/var/log;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/AC/wKiom1Xq8kGSR3B5AAG2xMy7u7Y231.jpg "/>

4. Delete the beginning of the line in the/tmp/functions file so #, and # followed by at least one blank character #;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/AC/wKiom1Xq8kLhiE5VAAG5BcaJK4A454.jpg "/>

file Lookup in the Find command exercise :

1, find the/var directory is the owner of the root, and belong to the group mail all files;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/A9/wKioL1Xq9GjQ79LJAABemZopDYE765.jpg "/>

2. Find all files that are not root, bin or hadoop under the/usr directory;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/AC/wKiom1Xq8kKx_FO9AABlWFyC2Hs896.jpg "/>

3. Find all files whose contents have been modified and are not root or Hadoop for the last week in/etc directory;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/A9/wKioL1Xq9GihGztxAABdpG_KDyg764.jpg "/>

4. Find all files on the current system that are not owned by the master or group, and have been visited in the last week;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/A9/wKioL1Xq9GnTwzl_AAHA6TMMVQc029.jpg "/>

5. Find all files of more than 20k and type of ordinary person in/etc directory;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/AC/wKiom1Xq8kSjzG6wAAO3E24cg_0176.jpg "/>

6, look for all the users in/etc directory do not have permission to write files;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/AC/wKiom1Xq8kXDvl2pAAKr_vOa7Nw549.jpg "/>

7. Find at least one class of users who do not have permission to execute files in/etc directory;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/A9/wKioL1Xq9GzDYsRnAAIUP_xysLE859.jpg "/>

8, find/etc/init.d directory, all users have execute permission, and other users have write permission files;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/AD/wKiom1Xq8kbglyyPAABVCqiy-rg739.jpg "/>

Exercises for Bash environment configuration :

1, so that ordinary users can use/tmp/cat to view/etc/shadow files;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/A9/wKioL1Xq9G3TYzozAALBOG83l2g741.jpg "/>

2, create the directory/test/data, let a group of ordinary users have write permission to it, and all the files created by the group of directories belong to the group, in addition, each user can only delete their own files;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/A9/wKioL1Xq9G7Tn9_rAAJgizT5h-c854.jpg "/>

Vim editor, find command and bash environment configuration

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.