Using the BASH environment variable for vim and find

Source: Internet
Author: User
Tags define local glob

What I brought to you today is vim,find, the use of commands, and some of the bash environment variables.

    • Vim command

      The VI command is the most common full-screen plain text editor in Unix operating systems and UNIX-like operating systems. The VI editor in Linux is called Vim, which is an enhanced version of VI, fully compatible with the VI editor, and features many enhancements.

      The VI editor has three modes: input mode, command mode (edit mode) and last line mode (by default, command mode is turned on)

      650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/9B/wKioL1XpPYSgNpwwAACZhNaNYbk308.jpg "title=" Sample Flowchart template.png "alt=" Wkiol1xppysgnpwwaaczhnanybk308.jpg "/>

Syntax: VI (OPTION) (parameter)

Parameter explanation:

  1. Ctrl+u: Half-screen to the top of the file;

  2. Ctrl+d: Half-screen to the end of the file;

  3. Ctrl+f: Turn over a screen at the end of the file;

  4. Ctrl+b: Turn one screen to the top of the file;

  5. ESC: Switch from edit mode to command mode;

  6. ZZ: Command mode to save the changes made by the current file after exiting VI;

  7. : line number: The cursor jumps to the beginning of the specified line;

  8. : $: The cursor jumps to the beginning of the last line;

  9. X or x: Delete one character, x after deleting the cursor, and x before deleting the cursor;

  10. D: Delete all the characters from the current cursor to the end of the line where the cursor is located;

  11. DD: Delete the line content of the cursor;

  12. NDD: Deletes the current line and its subsequent n-1 rows;

  13. Nyy: Saves the contents of the current row and its next n rows to the register? In, where? is a letter, n is a number;

  14. P: Paste text action to paste the contents of the buffer below the current cursor position;

  15. P: Paste the text action, which pastes the contents of the buffer area above the current cursor position;

  16. /string: Text lookup operation to find the contents of the specified string from the current cursor position to the end of the file, and the found string is highlighted;

  17. ? Name: Text lookup operation to find the contents of the specified string from the current cursor position to the head of the file, and the searched string will be highlighted;

  18. A,BS/F/T: The Replace text operation, which is used to change the F string to a T string, between line A and line B. where "s/" means a replacement operation;

  19. A: Add text after the current character;

  20. A: Add text at the end of the line;

  21. I: Inserting text in the current word match either;

  22. I: Inserting text at the beginning of the line;

  23. O: Insert a blank line after the current line;

  24. O: Insert a blank line before the current line;

  25. : Wq: In the command mode, the execution of the disk exit operation;

  26. : w: in command mode, perform disk operation;

  27. : w! : In command mode, execute the forced disk operation;

  28. : Q: In command mode, perform exit VI operation;

  29. : q! : Executes the forced Exit VI operation in command mode;

  30. : E file name: In command mode, open and edit files of the specified name;

  31. : N: In command mode, if you open more than one file at the same time, continue editing the next file;

  32. : F: In command mode, displays the current file name, the line number of the line where the cursor is located, and the display scale;

  33. : Set number: Used in command mode to display line numbers at the leftmost end;

  34. : Set nonumber: In command mode, used to not display line numbers at the leftmost end;

    • Find command

      Find and Localte are finding tools for their differences:

Locate: A non-real-time lookup tool that relies on a pre-built index, which is built automatically when the system is idle (periodic tasks), manually updating this database (updatedb), searching fast, and fuzzy lookups;

Locate-i ignoring case

Find: real-time lookup; find a bit slower; Find a file in the specified directory

Find syntax

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;

Find conditions Description:

    1. 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;

    1. According to the genus, the genus Group looks for:

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

-group GROUPNAME: Search by group

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

-gid GroupID: Finding files belonging to a group GID

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

-nogroup: Find files without a group;

    1. To find by file type:

Command parameters:-type Type

F: Normal file

D: Catalogue

L: Symbolic Link

B: Block device

C: Character device

P: Named Pipes

S: Socket

    1. Find criteria by combination:

and Conditions:-A

or condition:-O

Non-conditional:-not,!

    1. Depending on the file size, look for:

-size [+|-] #UNIT

Unit: K, M, G

Here are the various explanations for the 5 size file:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/B8/wKiom1Xr6TWR6YwbAAFAyDKk9S4041.jpg "title=" Qq20150906150758.png "alt=" Wkiom1xr6twr6ywbaafaydkk9s4041.jpg "/>

    1. Based on time stamp:

In "Days" as the unit

-atime, the last access time for the user.

-mtime the last modified time for the file.

-ctime the last modified time for file attributes, such as permissions, and so on.

In "Minutes" units

-amin

-mmin

-cmin

Here is how the time is expressed:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/B8/wKiom1Xr6-zwRzb0AAD0Rz337g4042.jpg "title=" Untitled. png "alt=" wkiom1xr6-zwrzb0aad0rz337g4042.jpg "/>



    1. Depending on the permissions of the file:

-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;

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


    1. Handling actions:

-print: Default processing action Print to screen

-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;

    • A brief introduction to the bash environment variables:

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 and 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 and Function:

(1) define command aliases; alias

(2) define local variables;

Environment variables: scope current shell process and its child processes

Local variable: scope current shell process

To define a local variable:

Name=value

View: Set

Define Environment variables:

Export Name=value

Declare-x name=value x The specified variable becomes an environment variable

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;

The most important is the configuration file order:

Interactive login:

Su-l username/etc/profile----/etc/profile.d/*.sh---~/.bash_profile Bashrc

Non-interactive logon:

SU username~/.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

Here are some practice questions:

    1. Copy the/etc/grub.cfg configuration file to the/tmp directory and use the Find and replace command to delete the white space character at the beginning of the/tmp/grub.cfg file ;

%s/^[[:blank:]]/#/g

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/9E/wKioL1XpYDWgLBpMAAHl-uGGE_w273.jpg "title=" 1.png " alt= "Wkiol1xpydwglbpmaahl-ugge_w273.jpg"/>

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

%s/^[[:blank:]]/#&/g

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/A2/wKiom1XpXjvDjpuwAAHDUbotl80582.jpg "title=" 2.png " alt= "Wkiom1xpxjvdjpuwaahdubotl80582.jpg"/>

    1. Replace the/etc/sysconfig/init in the/tmp/functions file as/var/log;

%s#/etc/sysconfig/init#/var/log#g

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/9E/wKioL1XpYNqyAunqAAFSnfl8Av4531.jpg "title=" 4.png " alt= "Wkiol1xpynqyaunqaafsnfl8av4531.jpg"/>

    1. Delete the beginning of the line in the/tmp/functions file so #, and # followed by at least one white-space character #;

%s/^#\ ([[: Space:]]\+\)/\1/g

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/A2/wKiom1XpXtbyZNfrAADJv9odXNw502.jpg "title=" 5.png " alt= "Wkiom1xpxtbyznfraadjv9odxnw502.jpg"/>

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


Find/var-user root-a-group Mail-ls
    1. Find all files that are not root, bin, or Hadoop under the/usr directory;

Find/usr! \ (-user root-o-user bin-o-user hadoop \)-ls
    1. Find all files whose contents have been modified and are not root or Hadoop for the most recent week in the/etc directory;

find/etc/-atime-7-A! \ (-user root-o-user hadoop \)-ls
    1. Find all files on the current system that are not owned by the master or group and have been visited in the last week;

find/etc/-atime-7-a-nouser-a-nogroup-ls
    1. Find all files that are larger than 20k in the/etc directory and are of the normal file type;

find/etc/-size +20k-a-type f-ls
    1. Find files in/etc directory where all users do not have permission to write;

FIND/ETC-! -perm/222-ls
    1. Find at least one class of users who do not have permission to execute files in/etc directory;

Find/etc-perm/111-type F-ls
    1. Find/etc/init.d directory, all users have execute permission, and other users have write permission files;

Find/etc/init.d-perm-111-a-perm-002-ls
    1. Allow ordinary users to use/tmp/cat to view/etc/shadow files;

chmod U+s/tmp/cat
    1. Create a directory/test/data, let a group of ordinary users have write permissions to it, and all the files created by the group is the directory belongs to the group, in addition, each user can only delete their own files;

# chmod g+s/test/data# chmod g+w/test/data# chmod o+t/test/data


Using the BASH environment variable for vim and find

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.