How to use Linux vim,find and disk and file system management

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

6, copy the/etc/grub.cfg configuration file to the/tmp directory, use the Find replacement command to delete the/tmp/grub.cfg file at the beginning of the blank character;

650) this.width=650; "title=" clip_image002 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image002 "src=" http://s3.51cto.com/wyfs02/M01/72/93/ Wkiom1xm1zpq8wy6aafozmnaqk4706.jpg "" 557 "height=" 298 "/>

7. 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; "title=" clip_image004 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image004 "src=" http://s3.51cto.com/wyfs02/M02/72/93/ Wkiom1xm1zsjqso4aadxgtkslti254.jpg "" 558 "height=" 285 "/>

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

650) this.width=650; "title=" clip_image006 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image006 "src=" http://s3.51cto.com/wyfs02/M00/72/93/ Wkiom1xm1zszhuafaadped8jim8026.jpg "" 558 "height=" 284 "/>

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

650) this.width=650; "title=" clip_image008 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image008 "src=" http://s3.51cto.com/wyfs02/M01/72/93/ Wkiom1xm1zsg1kmsaaczzfb5co8929.jpg "" 558 "height=" 285 "/>

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

650) this.width=650; "title=" clip_image010 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image010 "src=" http://s3.51cto.com/wyfs02/M02/72/93/ Wkiom1xm1zsxamctaabflksrqbu832.jpg "" 558 "height="/>

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

650) this.width=650; "title=" clip_image012 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image012 "src=" http://s3.51cto.com/wyfs02/M00/72/90/ Wkiol1xm2vaj38bqaacv-tgvsi0447.jpg "" 558 "height="/>

12, find the/test directory in the last week of its content has been modified, and is not the owner of root or Hadoop all files;

650) this.width=650; "title=" clip_image014 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image014 "src=" http://s3.51cto.com/wyfs02/M01/72/90/ Wkiol1xm2vnxj1-iaacgy0hzswq797.jpg "" 557 "height=" 137 "/>

13. 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; "title=" clip_image016 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image016 "src=" http://s3.51cto.com/wyfs02/M02/72/90/ Wkiol1xm2vmdvu5baadrjklsf2m981.jpg "" 558 "height=" 186 "/>

14. Find all files that are larger than 20k and type ordinary files in/etc directory;

650) this.width=650; "title=" clip_image018 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image018 "src=" http://s3.51cto.com/wyfs02/M00/72/90/ Wkiol1xm2vqdv3ooaagldvrqvac526.jpg "" 558 "height=" 281 "/>

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

650) this.width=650; "title=" clip_image020 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image020 "src=" http://s3.51cto.com/wyfs02/M01/72/90/ Wkiol1xm2vqargmkaacafrxyqbq691.jpg "" 557 "height=" "/>

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

650) this.width=650; "title=" clip_image022 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image022 "src=" http://s3.51cto.com/wyfs02/M01/72/93/ Wkiom1xm1zisx2vmaacqdgxvzvs167.jpg "" 558 "height=" 154 "/>

17, find/test directory, all users have execute permission, and other users have write permission files;

650) this.width=650; "title=" clip_image024 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image024 "src=" http://s3.51cto.com/wyfs02/M00/72/90/ Wkiol1xm2vrhwtixaab-m18s8cg762.jpg "" 557 "height=" 111 "/>

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

650) this.width=650; "title=" clip_image026 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image026 "src=" http://s3.51cto.com/wyfs02/M00/72/93/ Wkiom1xm1zni1skvaae0xneqwa0629.jpg "" 557 "height=" 261 "/>

19, 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; "title=" clip_image028 "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" clip_image028 "src=" http://s3.51cto.com/wyfs02/M01/72/93/ Wkiom1xm1zmqporgaagvdcxkdza396.jpg "" 558 "height=" 347 "/>

How to use Linux vim,find and disk and file system management

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.