Linux 17th Day Bash,find, Regular, command history

Source: Internet
Author: User
Tags aliases arithmetic first string function definition printable characters types of functions

Linux 17th Day

Time: 20180803


Directory

Script Test

$-variable Action

Bash's configuration file

Forgotten Content Review

Command history

Command history call

Bash arithmetic operations help let

Pipeline redirection

Regular expressions and extended expression meta-characters

Use of the Find command




Script Test


[x "$var = x" $var "] this way you can avoid prompting for syntax errors when null values are present in a variable

["$name" = "$test"] This is also to avoid null values for variables, but if two variables are empty, they will be true.

[["$var" =~ EXPR]] supports extended regular expression matching, followed by regular non-quoted


Script does not support aliases: Aliases in scripts that do not execute commands


Read and user interactively assign a value to a variable

-P adds a hint string when assigning a value to a variable

-n Specifies the character length of the variable, which is automatically saved to the variable when the user input character length is reached, instead of waiting for the user to press ENTER

-S user input does not display characters entered by the user, generally used to set the password

-d Specifies the end symbol, which automatically saves the string to the variable when the specified end character is entered

-t Specifies the wait time, when the user does not output characters for a long time, automatically exits the interactive interface, the variable is a null value


$-variable Action

This variable is a monitoring variable that can show the current bash configuration

Echo $-displays a string with each character representing the function that bash opens

H Hashall has this character to indicate that the shell will hash the path of the command and avoid searching the hard drive path every time

The h option is turned off via set +h

I interactive-comments contains this option to show that the current shell is an interactive shell. The so-called interaction

Shell, in the script, I option is off

M monitor turns on monitoring mode, and you can control the process stop, resume, background, or foreground by using job control

Performing BG FG

B Braceexpand curly Braces {} expands, and if closed the curly braces are recognized as normal strings

The H history H option opens, you can expand the commands in the historical list, and you can go through! Execute its history command,

It cannot be executed if it is closed. Set +|-H



Bash's configuration file

By the effective scope, there are two types of

Global configuration:

/etc/profile

/etc/profile.d/*.sh

/etc/bashrc

Personal configuration:

~/.bash_profile

~/.bashrc


There are two types of functions divided by function

Profile class: Provides configuration for the interactive logon shell

Global:/etc/profile/etc/profile.d/*.sh

Personal: ~/bash_profile


Function: Define an environment variable to run a command or script


BASHRC class: Provides configuration for non-interactive and interactive logon shells

Global:/ETC/BASHRC

Personal: ~/.BASHRC


Function: Define command aliases and function definition local variables



The order in which the configuration files are read when the shell logs on

Interactive Login

1) Enter your account password directly through the terminal login

2) users who switch with "Su-user"

Order of execution:/etc/profile-/etc/profile.d/*.sh-~/.bash_profile

--~/.BASHRC-/ETC/BASHRC


Non-interactive Login

1) Su UserName

2) Open terminal under graphical interface

3) Execute script

4) Any other bash instance

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


Bash quits task

This file is read and executed when the user exits the login ~/.bash_logout


Function: Create automatic Backup to clear temporary files, etc.



Locate through the database to find files in the system cent7 minimal installation has discarded this package mlocate

-I ignore case ignores character capitalization

-N followed by a numeric representation of the first # files to be displayed

-R can be followed by a basic regular expression to search for files

UpdateDB This command is used to update the file query database, and this command can be used to update the system if a new file is generated

Database



Forgotten Content Review


Command history

!! Executes the previous command

!-1 executing the previous command

!n command to execute the history command output corresponding to the ordinal n

!-n executes every nth command in history

!string repeat the previous command that starts with "string"

!? String repeats the previous command that contains "string"

!string:p only print commands without performing

!$:p Print out the contents of the!$ (last parameter of the previous command)

!*:p the contents of the PrintOut!* (all parameters of the previous command)

^string Delete the first string in the previous command

^string^string2 Replace the first string1 in the previous command with string2

!:gs/string1/string2 Replace all string1 in the previous command with string2

History command Invocation

Ctrl+r can search for historical commands that contain a string

Ctrl+g exit from command history search mode

Command!^ invokes the first parameter of the previous command as the command parameter

Command!$ invokes the last parameter of the previous command as a parameter of command

Command!* invokes all parameters of the previous command as arguments to command

Command!:n invokes the nth parameter of the previous command as a parameter of command

Command!n:^ invokes the first parameter of the nth command as a command parameter

Command!n:$ invokes the last parameter of the nth command as a command parameter

Command!n:m invokes the M parameter of the nth command as a parameter of command

Command!n:* to invoke all arguments of the nth command as arguments for command



Bash arithmetic operations help let

+,-, *,/,% modulo, * * exponentiation

syntax to implement arithmetic operations

A=5 b=8

1) Let c= $a + $b

2) c=$[$a + $b]

3) c=$ (($a + $b))

4) c=$ (expr $a + $b)

5) echo $a + $b |BC

Multiply symbols Some scenes need to be escaped in front of them plus \



Pipeline redirection

> redirect standard output to a file to overwrite its original content

>> redirects the standard output to a file but does not overwrite its original content, appended to it

2> redirect the error output to a file to overwrite its original content

2>> redirects the error output to a file but does not overwrite its original content, appended to it

&> redirect Standard and error output to a file to overwrite its original content

&>> redirects the standard and error output to a file but does not overwrite its original content, appended to it

2>&1 to go to standard output for error output

1>&2 switch standard output to error output

Example LS ABC >f1 2>&1


Regular expressions and extended expression meta-characters

Standard Regular Expressions

Character matching

. Any single character

[] matches any single character in parentheses

[^] matches any single character except in parentheses

[: Alnum:] Letters and numbers

[: Alpha:] uppercase and lowercase letters

[: Upper:] Uppercase

[: Lower:] lowercase letters

[:d Igit:] Number

[:p UNCT:] Punctuation

[:p rint:] printable characters

[: Space:] Space

[: Blank:] white space character


Number of Matches

* matches the preceding character any time including 0 times

\? Match Front character 0 or 1 times

\+ match front character at least 1 times

\{n\} matches the preceding character n times

\{n,\} matches the preceding character at least n times

\{n,m\} matches the preceding character at least n times, up to M times

\{,m\} matches the front character up to M times

Position anchoring

^ Beginning of the line

$ End of line

\< or \b Word head

\> or \b Ending

Or

\| Represents one of the patterns that match the front or rear

Group

\ (\) encloses a set of expressions that you can use to back-reference

It is important to note that a back reference is a character that matches the pattern in the block brackets in front of the reference, not the pattern itself

Extending regular Expressions

Character matching

. Match any single character

[] matches any single character in parentheses

[^] matches any single character except in parentheses

Number of Matches

* matches the preceding character any time including 0 times

? Match Front character 0 or 1 times

+ Match Front character at least 1 times

{n} matches the preceding character n times

{N,} matches the preceding character to less than n times

{n,m} matches the preceding character at least n times, up to M times

{, m} matches the forward character up to M times

Position anchoring

^ Match beginning of Line

$ Match Line End

\< or \b matches the first word

\> or \b Match ending

Or

| Represents one of the patterns that match the front or rear

Group

() surround a set of expressions that you can use to back-reference


Basic regular and extended regular differences

In basic regular Expressions the meta-characters?, +, {, |,

(, and) lose their special meaning; Instead use the backslashed

Versions \?, \+, \{, \|, \ (, and \).


The default basic regular, +, {, |, (,), has special meaning in the shell so precede it with \ Add its

Escaped, which is not recognized by the shell as a special character. And the extension is optimized so that it can be used directly

Characters that are not recognized by the shell as special meanings.



Find files or folders on a file system

-maxdepth level maximum Search directory depth, specified directory 1th

-mindepth level minimum Search directory depth

-iname is case-insensitive when searching for file names

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

-empty search for empty files or empty directories

Fine/app-type D-empty

-perm +|-#

# indicates exact matching of the given permissions

For example,-perm 644 exactly matches files or folders with file permissions of 644

/# represents a set of matching permissions that can be

If the-perm/644 match file permissions are greater than 6 or belong to a group greater than 4 or other files greater than 4 or

Folder

-# that matches each bit in the given permission

If-perm-644, the matching file permission belongs to the master at least 6 and belongs to the group of at least 4 other 4 files or

Directory

/|-664 110 110 100

/110 110 100 means 1 Care 0 does not care if there are or not all can be between each 1 groups for or relationship

Can be matched with 777, 600, 060, 004, etc. as long as there is a set of satisfaction can

-110 110 100 means that 1 care 0 does not care if there is nothing that can be between each 1 group for the relationship

Can match 664, 764, 667, 665 and other three groups of permissions at the same time more than 664 to meet

-atime # Unit is day

# means [#,#+1] not much in this way, generally +--use more

If-atime 5 means that the file was accessed within 5 days and 6 days ago

+# = [#+1, Infinity]

If-atime +5 represents 6 days (including every 6 days) of files that have been accessed before

-# said (#,now)

If-atime-5 represents a file that has been accessed within 6 days

-ctime

-mtime

-amin # units are minutes

-cmin

-mmin

-size +|-#UNIT

#UNIT (#-1,#]

If 5 k means (4k,5] match 4k-5k size file

-#UNIT [0,#-1]

As -5k means [0,4k] means matching files less than or equal to 4K size

+ #UNIT

As +5k means (5K, infinity) to match files larger than 5K in size

-prune

Find all the. conf suffix files under/etc/, except/ETC/SANE.D and/etc/fonts two directories

FIND/ETC \ (–path '/etc/sane.d ' –o–path '/etc/fonts ' \) \

-a-prune–o-name "*.conf"


Linux 17th Day Bash,find, Regular, command history

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.