Some common commands about the shell

Source: Internet
Author: User

Ls-lat list all the stuff in the current directory
Ls-lath people look at the size
Ls-f | grep "/$" only Directory
LS-LR include subdirectories ...
LS--ignore filename-lt ignores a


Which, in the path specified by the path variable, searches to see if a command exists, and which command executes exactly which location.
Whereis, search for the program name, and search only for binaries, man documentation, and source code files. If the argument is omitted, all information is returned.
Locate, specify the file name in the system-specific database, such as CentOS it only at a certain time of the day to update the new files to/var/lib/mlocate/mlocate.db this database, the timing see/etc/cron.daily/ Mlocate.cron,strings can see some of the content
There are some useful tools such as tree,file,type, etc.


-mtime modification Time
-type File types
-mmin Modify Minutes
-perm Permissions
-user Users
-group Group
-maxdepth Hierarchy of Search catalogs
...
Look for more, man.



Find. -maxdepth 1-type F! -name "*.txt"
Find a normal file that is not a. txt in a directory of Level 1 (current directory)
Find. -maxdepth 1-type f \ (-name "*.txt"!-name "Haha.txt" \)
Find A. txt but do not include files like. haha.txt
Find. -maxdepth 1-type f \ (-name "*.php"-o-name "*.txt" \)
Find. php or. txt files


-exec will receive all of the files found match to the one-time operation, unfortunately, some systems can be passed to the EXEC command length limit, there will be overflow error, such as prompt "Argument list too long"
Getconf Arg_max look at the byte limit of the parameter
So what?


The Xargs xargs command takes only a subset of the files at a time, not all, unlike the-exec option. This allows it to first process a portion of the file that was first fetched, then the next batch, and so on.
Find. -name "*.txt" | Xargs-n Ls-lat
Find. -name "*.txt" | Xargs-i file-n 1 mv File File.log better understanding of the expression


Find lookup avoids a directory
Find. -path "./subdir*"-prune-o-type f-name "*.txt"-print
Locate the/update/directory but do not include subdirectories./subdir the following things
What does it mean? Personal Understanding:
Don't be-path confused, in fact-path is-wholename, here with-wholename "./subdir*" the same.
-depth and-prune conflict, there are-depth words-prune failure
Can be expressed in pseudo-code:
Find ... Get a good long and long string ...
In a long string of this.
if (-path "./subdir*")
Then
-prune #切切切
Else (Find-type f-name "*.txt")
-print
Avoid multiple directories
Find. -path './subdir '-prune-o-path './subdir1 '-prune-o-path './subdir2 '-prune-o-path './subdir3 '-prune-o-name ' *.tx T "-print
Jane writes the following:
Find. \ (-path './subdir '-o-path './subdir1 '-o-path './subdir2 '-o-path './subdir3 ' \)-prune-o-name "*.txt"-print


Grep-n a *.txt
Display matching lines and line numbers
Grep-c a *.txt
Output only the count of matching rows
Grep-v a *.txt
Does not contain a match
grep ' \<abcd\> ' *.txt
Exact match A
grep ' [a-z][a-z][0-9] ' *.txt
Print content similar to "AB1" to support POSIX regular
grep ' [A-z]\{4,\}log ' *.txt
Print lowercase letters Repeat more than four times for lines, such as AAAA,AABBC, etc.
Grep-v ' ^$|^# ' *.txt
Filter lines with lines beginning with # (usually comments)
Grep–a5–b5 ' haha ' *.txt
Prints lines matching to ' haha ' and the last 5 rows, the next 5 lines
grep ' 192.168.100.34:3306|pfantasy ' –r/usr/local/wwwroot/
can also be written egrep-e ' 192.168.100.34:3306 '-e ' pfantasy '-r/usr/local/wwwroot/
grep ' 192.168.100.34:3306.*pfantasy '-r/usr/local/wwwroot/


awk statements are made up of patterns and actions
The pattern section determines the timing of finding objects, usually consisting of a conditional statement or regular, consisting of two special fields: begin{} and end{}
The action is in some cases what to do ...
begin{} is generally used as a tab before any text-browsing action, and end{} is used to perform text browsing and is typically used as a statistical
So the general structure is: awk ' begin{predefined points what} {formally do something} {and do something} ... End{finish the summary report point what} '


$ ...
All, action by default print all
The usual field delimiter is a space or \ t
awk ' begin{print ' Hello---------\ n "}{print $1,$2}end{print" Byebye----------\ n "} ' A.txt


The action section may have some conditions or loops.
awk ' {if (XX) print $} ' a.txt
awk ' {for (OO) print $} ' a.txt
About matching
Come first.
awk ' {if ($ ~/d/&& $ ~/[hh]aoren/) print $} ' a.txt
Come again.
awk ' {if ($ ~/d/&& $ = = "Haoren") print $} ' a.txt
In fact, the above two can be written, because the action is the default print
awk ' $/d/&& $/[hh]aoren/' a.txt
awk ' $/d/&& $ = ' Haoren ' a.txt
awk ' begin{ignorecase = 1;} {if ($ ~/d/&& $ ~/[hh]aoren/) print $} ' a.txt ignores case


sed, like awk, is also the flow editor
SED has two spaces
Pattern space, sed defaults to print mode space without the-n (suppress automatic printing of the pattern space) parameter. Typically, each row of records is passed through the mode space only once.
Hold space temporary storage spaces, transit places, such as the pattern space to the temporary storage space, and then the mode of space to inject new things, and then go to the temporary storage space to take out.


Internal operations common to SED
N reads the next line to replace the row of the current pattern space.
N reads the next line and appends it to the pattern space line, where there are two lines of pattern space but only a lump of stuff.
H copies the rows in the pattern space to the staging space.
H appends rows in the pattern space to the staging space.
G Replace the rows of the pattern space with the contents of the staging space.
G appends the contents of the staging space to the lines of the pattern space.
X swaps the contents of the staging space with the content in the pattern space.
! Applies a command to all rows except the selected row.
P Prints the contents of the current mode space.
D Delete the mode space and start the next operation from the beginning.
D Delete the first segment of the line break in the pattern space and start the next operation from the beginning.
$ match last line


Some exercises
Add a blank line after each line
Append to the pattern space with an East that remains null (including \ n)
Sed ' G ' a.txt
Add a blank line before matching rows
Because of the addition of the line, it is actually printing null and then printing the row contents, so you need x to exchange a null. After matching the line, the pattern space is thrown into the scratch space (x), so the pattern space is currently null, print it, and then change back, mode space for the previous content, automatic printing mode space.
Sed '/aaa b/{x;p;x;} ' a.txt
Print odd lines
Have skip operation, to with n/n related, not print is delete D bar
Sed ' {n;d} ' D.txt
Sed-n ' {p;n} ' D.txt
Sed ' 0~2d ' d.txt
Print even rows
Sed-n ' {n;p} ' D.txt
Sed ' 1~2d ' d.txt
Add an empty line after even lines
Sed ' {n; G} ' D.txt
Even line blank
Sed ' {n;g} ' D.txt


Nohup Command &
Screen
Crontab
Expect
...

Some common commands about the shell

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.