Linux OPS Practice-August 30, 2015 Course assignments

Source: Internet
Author: User
Tags glob string find

Linux OPS Practice-August 30, 2015 Course assignments

1, summarize the text editing tool vim use method;

Vim: Full-screen editor;

Vim's editing mode:

Edit mode: Command mode; The two meanings are probably the same.

Input mode, last-line mode.

Edit mode (switch to) input mode:

Insert:i

Append:a

New Line:o

Beginning of line: I

End of line: A

New row above: O

Input mode à edit mode:

Esc

Edit mode, last-line mode:

Last-line mode à edit mode:

Esc

How to open the Vim editing tool:

Vim/path/to/somefile

+#: #为行号;

+/:pattern

Turn off VIM:

: Q Do not save exit;

: q! Forced exit;

: Wq save exit;

: W A1 save file as A1:zz save file and exit, equivalent to: wq:wq! The file owner forces the read-only file to be saved and cannot succeed if the file owner does not do this

Copy (Yank)

Command mode:

yy or y Copy the entire line y^ copied to the beginning of the line of the cursor, excluding the cursor position character y$ copied to the end of the line of the cursor, including the cursor position character yw copy a word, the cursor must be in the first YG copy to the end of the file y1g copied to the top of the file Nyy copy cursor row beginning of n line

Paste

Command mode P (lowercase) Paste to cursor after P (uppercase) paste to cursor before delete command mode x (lowercase) Delete cursor before one character x (uppercase) Delete cursor after one character dd (lowercase) Delete cursor in full line DW (lowercase) Delete cursor where the word DG deletes the entire line at the end of the file DGG delete the entire line of the cursor to the beginning of the file D (upper case) Delete to the end of the line, including the character at the cursor d$ the same as the D effect D0 deleted to the beginning of the row, not including the character at the cursor d^ with the same D0 effect: n1,n2d edit mode, delete n1-n2 row undo

Command mode u (lowercase) unlimited save before saving (approximately 500 times) Ctrl+r Redo

In the character substitution command mode, the R (lowercase) replacement cursor is located at the beginning of a character R (uppercase) substitution, until you press ESC to exit the replacement, which is equivalent to pressing the keyboard to insert cc (lowercase) instead of the entire line S (uppercase) with the SS (lowercase) effect the same as C (uppercase) to the end of the line Includes the character c0 (lowercase, number 0) at the cursor instead of the beginning of the line, excluding the character c^ (lowercase) at the cursor and the same effect as c0 (lowercase, number 0)

String find and Replace command mode/string start from the cursor down to find the string, click N (lowercase) to find the next, and then press N (uppercase) to find the previous? string starts at the cursor to find the character from the string? Find mode press N (lowercase) Find Previous, press N (uppercase) to find Next * down full match cursor under word # up full match cursor under word g* down part match cursor under word g# up part match cursor down to Word input mode:: When set IC lookup, ignore case: Set Noic ignore large when lookup is canceled Lowercase: F string (lowercase f with string with a space) searches for a string that matches in a row:%s/old/new/g full text replaces old with new, without prompting:%s/old/new/c full text replaces old with new, prompting for replacement: n1,n2s/ old/new/g n1-n2 Line, replace old with new, do not prompt: n1,n2s/old/new/c n1-n2 line, replace old with new, prompt to replace in replace text old or new with/characters, need \ to escape

Cursor movement mode H (uppercase, Head) moves to top of screen the first non-whitespace character M (uppercase, Mid) moves to the middle of the screen the first non-whitespace character L (uppercase, last) moves to the bottom of the screen the first non-whitespace character ((left parenthesis) moves to the top of the previous sentence) (right parenthesis) moves to The next sentence first {(opening brace) moves to the previous paragraph first} (closing curly brace) moves to the next paragraph first% cursor jumps to match to parentheses, supports {} () [[Cursor jumps to code block at the beginning of {, requires {exclusive line of GD cursor jumps to local variable definition ' (two single quotes) cursor jumps to last The stop h (lowercase) cursor moves left one character, which is equivalent to the left ARROW key L (lowercase) cursor to the right one character, equivalent to the right ARROW key K (lowercase) cursor up a line vertically, equivalent to the upper arrow key J (lowercase) cursor down a line vertically, equivalent to the next arrow key ctrl+f (ForWord) down the full page of CT Rl+b (backward) Up full page ctrl+u (UP) upside down half page ctrl+d (down) Flip half page zz (lowercase) Place the cursor line in the center of the screen ZT (lowercase) so that the cursor is located at the top of the screen ZB (lowercase) so that the cursor line at the bottom of the screen input Mode:

: n Specifies move to nth row

Turn screen operation:

Ctrl+f: one screen backward;

Ctrl+b: one screen ahead;

Ctrl+d: Back half screen

Ctrl+u: Forward half screen

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

Ii. Summary Document Find command how to use

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;

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;

Cp/etc/grub.cfg/tmp

Vim/tmp/grub.cfg

:%s/^\s*//g

650) this.width=650; "title=" wpsc40f.tmp "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=" wpsc40f.tmp "src=" http://s3.51cto.com/wyfs02/M02/72/9A/ Wkiol1xpbavb9ieuaaerx5vhvpc955.jpg "" 491 "height=" 349 "/>

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;

[Email protected] ~]# cp/etc/rc.d/init.d/functions/tmp/

[Email protected] ~]# vim/tmp/functions

:%s/^\s/#&/g

650) this.width=650; "title=" wpsc420.tmp "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=" wpsc420.tmp "src=" Http://s3.51cto.com/wyfs02/M00/72/9A/wKioL1XpBayg_ Ry0aaecfzxyam0668.jpg "" 425 "height="/>

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

650) this.width=650; "title=" wpsc421.tmp "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=" wpsc421.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/9A/ Wkiol1xpbaybedvfaacqhnwmwa8414.jpg "" 528 "height=" 196 "/>

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

:%s/^#\s//g

650) this.width=650; "title=" wpsc431.tmp "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=" wpsc431.tmp "src=" http://s3.51cto.com/wyfs02/M02/72/9A/ Wkiol1xpba3qqf0saadrdd8mkrg053.jpg "" 475 "height=" 249 "/>

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

[Email protected] var]# find-user root-group Mail

650) this.width=650; "title=" wpsc442.tmp "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=" wpsc442.tmp "src=" http://s3.51cto.com/wyfs02/M00/72/9A/ Wkiol1xpba3gs1tuaab0g3dde5o012.jpg "" 593 "height=" 124 "/>

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

[[email protected] var]# Find-not-user root \ (-not-user bin-o-user hadoop \)

650) this.width=650; "title=" wpsc443.tmp "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=" wpsc443.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/9A/ Wkiol1xpba2temodaadh-0ksl5y663.jpg "" 513 "height=" 280 "/>

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

[[email protected] var]# find-mtime-7 \ (-not-user root-o-user hadoop \)

650) this.width=650; "title=" wpsc444.tmp "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=" wpsc444.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/9D/ Wkiom1xpa4maz3-5aadtgr8vxlq857.jpg "" 515 "height=" 247 "/>

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;

[[email protected] ~]# Find/-type f-mtime-7 \ (-nouser-o-nogroup \) – LS

650) this.width=650; "title=" wpsc445.tmp "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=" wpsc445.tmp "src=" http://s3.51cto.com/wyfs02/M02/72/9D/ Wkiom1xpa4rbx5t8aadgsp2-1zq267.jpg "" 550 "height="/>

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

[Email protected] etc]# Find-type f-size +20k-ls

650) this.width=650; "title=" wpsc455.tmp "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=" wpsc455.tmp "src=" Http://s3.51cto.com/wyfs02/M00/72/9D/wKiom1XpA4qgVm5NAAHLdlH _7ce237.jpg "499" height= "/>"

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

[Email protected] ~]# Find/etc-type F-not-perm/222–ls

650) this.width=650; "title=" wpsc456.tmp "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=" wpsc456.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/9D/ Wkiom1xpa4uhof1vaafajmfu_l8052.jpg "" 486 "height=" 247 "/>

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

[Email protected] ~]# Find/etc-type F-not-perm-111-ls

650) this.width=650; "title=" wpsc467.tmp "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=" wpsc467.tmp "src=" http://s3.51cto.com/wyfs02/M02/72/9E/ Wkiom1xpa4utequnaagvzvwoply494.jpg "" 514 "height=" 293 "/>

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

[Email protected] etc]# Find Init.d-perm/113-ls

650) this.width=650; "title=" wpsc468.tmp "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=" wpsc468.tmp "src=" http://s3.51cto.com/wyfs02/M02/72/9E/ Wkiom1xpa4zb2kghaadn0kgcgj8597.jpg "" 602 "height=" 196 "/>

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

Because my virtual machine inside before I do the test/tmp/cat for files, so to keep, in/var under the CP one.

Cp/bin/cat/var copy Cat to/var directory, because my cat is under the bin, everyone may be different, and then test the root user can use the/var/cat command to view the/etc/shadow file, to the user bash, test discovery denied , back to the root user, for/tmp/cat to do permission settings: chmod o+s/var/cat, ordinary users can/var/cat perform administrator rights

650) this.width=650; "title=" wpsc469.tmp "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=" wpsc469.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/9A/ Wkiol1xpbbdslw4kaae0elebrd4890.jpg "" 550 "height=" 261 "/>

650) this.width=650; "title=" wpsc47a.tmp "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=" wpsc47a.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/9E/ Wkiom1xpa4zrg3ceaaez5q65hie659.jpg "" 552 "height=" 203 "/>

650) this.width=650; "title=" wpsc47b.tmp "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=" wpsc47b.tmp "src=" http://s3.51cto.com/wyfs02/M02/72/9E/ Wkiom1xpa43azlglaag-xihlve4751.jpg "" 561 "height=" 271 "/>

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;

First I created the group: MYGRP, then create the user: Qiuye1,qiuye2, and add the additional group Mygrp to two users, and then set the permissions on the/mydata/data directory, the normal user can write but not delete the other user files: chmod o+t And then test the results on the QIUYE1 User:

650) this.width=650; "title=" wpsc47c.tmp "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=" wpsc47c.tmp "src=" http://s3.51cto.com/wyfs02/M00/72/9E/ Wkiom1xpa43baquwaadi3u2ku1g324.jpg "" 463 "height=" 172 "/>

650) this.width=650; "title=" wpsc48c.tmp "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=" wpsc48c.tmp "src=" http://s3.51cto.com/wyfs02/M01/72/9A/ Wkiol1xpbblciuxdaadwjnqsmnu185.jpg "" 477 "height=" 174 "/>

Linux OPS Practice-August 30, 2015 Course assignments

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.