Summary of Common Linux commands

Source: Internet
Author: User
Tags bz2 rar domain name server

Query command find
* Find [specify find directory] [find rule] [action executed after find]

* Find ~/.m2-name "*.lastupdated"-exec grep-q "Could not transfer" {} \; -print-exec rm {} \;(find files with lastupdated suffix that contain "could not ..." file, print and delete him) (' * ' means to wildcard any character;? Indicates a wildcard of any single character)

*-iregex/regex (followed by regular expressions, I ignore case)

*-user//search for files according to owner

*-group//According to the genus Group to find files

*-a And-o and–not//Connect multiple conditions,-A is with relationship,-O is or relationship,-not is take reverse

*-atime;-mtime;-ctime;-amin;-mmin;-cmin//Here Atime,mtime,ctime is the corresponding "Last access time" Last content modification Time "Last Property modification Time", Here the unit of Atime refers to "days", Amin units are minutes (find/tmp–atime +5//means to find files that have not been accessed within five days; find/tmp-atime-5//means to find files accessed within five days)

*-type//According to file type to find files (f ordinary files; d directory files; l link files; b device files; C-character device files; P pipeline file; s socket file)

*-size//Based on file size to find Files ("Find/tmp-size 2M" Find files equal to 2M in/tmp directory; +2m, greater than; -2m, less than)

*-perm//Based on file permissions to find Files ("Find/tmp-perm 755" Find files in the/tmp directory with permissions of 755)

* [Find out the action of execution]
["-print" action by default; " -ls "Find and then use LS to display it;" -ok [commend] "Search after the execution of the command to ask the user whether to execute;"-exec [commend] "Search after the execution of the command without asking the user, direct execution]

* "Find/tmp-atime +30–exec rm–rf {} \;"//delete found more than 30 days without access to the file

* "Find/tmp-iregex". *.   [Sh,bat] "-exec cp {} {}.old \;" Replaces the found file, leaving the source file (mv not retained)
Locate
Locate command and find find files similar function, but locate is through the update program to the hard disk all the files and directory data first set up an index database, in the execution of LOACTE directly to find the index, query faster, the index database is generally managed by the operating system, However, you can also directly release the update to force the system to immediately modify the index database.

Locate [option] [pattern]
Less
The less tool is a tool for paging through files or other outputs (it is recommended to use the pipeline for other outputs, file vim processing), to provide front and rear paging capabilities, and to search for functions.

-b [Buffer size] Sets the size of the buffer

-e When the file display is finished, automatically leave

-F forcing special files to be opened, such as peripheral code, directories, and binaries

-G only flags the last keyword searched

-I ignores case when searching

-m shows a percentage similar to the more command

-N Displays the line number of each line

-o [filename] saves less output in the specified file

-Q does not use warning tones

-S displays a row of continuous empty behavior

-S line too long will be out of the partial discard

-X [number] Displays the "tab" key as a specified number space

/string: Search down the function of "string"

String: The ability to search up "string"

N: Repeat the previous search (with/or?). About

N: Reverse repeats the previous search (and/or?) About

b Turn back one page

D Turn back half a page

H Display Help interface

Q Exit less command

U scroll forward Half page

Y Scrolls forward one line

SPACEBAR Scrolls one page

Enter to scroll one line

[PageDown]: Flip one PAGE Down

[PageUp]: Flip one page Up

which
The purpose of the which command is to search for the location of a system command in the path specified by the path variable, and return the first search result. That is, with the which command, you can see whether a system command exists, and the command that executes exactly which location.

Whereis
The Whereis command can only be used for program name searches, and only binary files (parameter-B), man description file (parameter-m), and source code file (parameter-s) are searched. If the argument is omitted, all information is returned. (Eg:whereis-b Tomcat)

The Whereis lookup is very fast compared to find, because the Linux system records all the files in the system in a database file, and when you use Whereis and locate, you look for data from the database instead of traversing the hard disk like the Find command to find , the efficiency will naturally be very high.
However, the database file is not updated in real time, and is updated once a week by default, so when we use Whereis and locate to find files, we sometimes find data that has been deleted, or just created the file, but cannot find it because the database file is not updated.
Tail
The tail command writes the file to standard output starting at the specified point. Using the-f option of the tail command makes it easy to see the log files that are being changed, TAIL-F filename will display the most up-to-date contents of the filename on the screen, and not only refresh, so you can view the latest file content.

tail[necessary parameters [selection parameters] [file]
-F Loop Read

-Q does not display processing information

-V displays detailed processing information

Number of-c[] bytes displayed

-n[rows] shows the number of rows

–pid=pid is shared with-F, which means that the process ends after the id,pid dies.

-q,–quiet,–silent never outputs the header of a file name

The-s,–sleep-interval=s is combined with-F, which indicates the sleep s seconds at each repetition interval

Grep
grep (Global search Regular expression (RE) and print out of the line, full search of regular expressions and print out rows) is a powerful text search tool that uses regular expressions to search for text. and print out the matching lines.

grep [Options] ... PATTERN [FILE] ...
-N indicates the column number before displaying the column that conforms to the template style.

-Q does not display any information.

-r/-r the effect of this parameter is the same as specifying the "-D recurse" parameter.

-e [Template style] Specifies a string as the template style for finding the contents of a file.

-E uses the template style as an extended normal notation, which means that extended regular expressions can be used.

-F [Template file] Specifies a template file with the contents of one or more template styles that let grep find the contents of a file that conforms to the template criteria, in the form of a template style for each column.

The regular syntax supported by grep
^ The start of the anchor line, such as: ' ^grep ' matches all lines that begin with grep.

$The end of the anchoring line is as follows: ' grep$ ' matches all rows ending with grep.

. Match a non-newline character such as: ' GR.P ' matches gr followed by an arbitrary character followed by P.

* Match 0 or more previous characters such as: ' *grep ' matches all of one or more spaces followed by the grep line. * Together with any character represented.

[] matches a specified range of characters, such as ' [Gg]rep ' matches grep and grep.

[^] matches a character that is not within the specified range, such as: ' [^a-fh-z]rep ' matches a letter that does not contain a-r and t-z, immediately following the line of the Rep.

\(.. \) tag matching characters, such as ' \ (love\) ', Love is marked as 1.

\ Anchors the beginning of a word, such as: ' \ matches a line containing a word that begins with grep.

\> anchors the end of the word, such as ' grep\> ' matches the line that contains the word that ends with grep.

X\{m\} repeats characters x,m times, such as: ' 0\{5\} ' matches rows containing 5 O.

X\{m,\} repeats a character x, at least m times, such as: ' O\{5,\} ' matches at least 5 rows of O.

X\{m,n\} repeats the character x, at least m times, not more than n times, such as: ' O\{5,10\} ' matches rows of 5–10 O.

\w matches literal and numeric characters, that is, [a-za-z0-9], such as: ' G\w*p ' matches with a G followed by 0 or more literal or numeric characters, followed by P.

\b Word lock, such as: ' \bgrep\b ' only matches grep.

eg
Ls-r Find Directory | grep "file name with character" (Recursive lookup under current folder, specify file name)

Grep-r "word" "dir" ("word" in all files under the recursive folder)

Grep-e "[1-9]+" Equals Egrep "[1-9]+"
Other Commandchmod
The chmod command is used to change access rights for Linux system files or directories. Use it to control access to files or directories. This command is used in two ways: one is a text-setting method that contains letters and operator expressions, and the other is a digital setting method that contains numbers.

chmod [-CFVR] [help] [–version] Mode file
Permission range:
U: The current user of the directory or file
G: The current group of directories or files
O: Users or groups other than the current user or group of directories or files
A: All Users and Groups
Permission code:
R: Read permission, denoted by the number 4
W: Write permission, denoted by the number 2
X: Execute permission, denoted by the number 1
-: Delete permission, denoted by the number 0
S: Special permissions ([Special permissions] (http://alan-hjkl.iteye.com/blog/1526858))

Tar Many of the compressors in the
linux can only be compressed for one file, so when you want to compress a whole bunch of files, you have to first make a package (Tar command) of the whole bunch of files. Then compress with the compression program (gzip bzip2 command).

Common Insights Compression/compression command
Tar
Unpacking: Tar xvf filename.tar
Package: Tar cvf filename.tar DirName
(Note: Tar is packaged, not compressed!)
. GZ
Decompression 1:gunzip filename.gz
Decompression 2:gzip-d filename.gz
Compression: gzip FileName
. tar.gz and. tgz
Decompression: Tar zxvf FileName.tar.gz
Compression: Tar zcvf FileName.tar.gz DirName
. bz2
Unzip 1:bzip2-d filename.bz2
Unzip 2:BUNZIP2 FILENAME.BZ2
Compression: Bzip2-z FileName
. tar.bz2
Decompression: Tar jxvf FileName.tar.bz2
Compression: Tar jcvf FileName.tar.bz2 DirName
. BZ
Decompression 1:bzip2-d filename.bz
Decompression 2:bunzip2 filename.bz
Compression: Unknown
. TAR.BZ
Unzip: Tar jxvf FILENAME.TAR.BZ
Compression: Unknown
. Z
Extract: uncompress filename.z
Compression: Compress FileName
. Tar. Z
Extract: Tar zxvf filename.tar.z
Compression: Tar zcvf filename.tar.z DirName
. zip
Decompression: Unzip filename.zip
Compression: Zip Filename.zip DirName
. RAR
Decompression: rar x filename.rar
Compression: rar a filename.rar DirName
Netstat
The netstat command is used to display statistics related to IP, TCP, UDP, and ICMP protocols, and is typically used to verify the network connectivity of each port on the machine.

netstat [-accefghilmnnoprstuvvwx][-a [Network type]][–IP]

Command parameters:
-A or –all shows all sockets in the connection.
-a[Network Type] or –[network type] lists the relevant addresses in this network type connection.
-C or –continuous continues to list network status.
-C or –cache displays the cache information for the router configuration.
-E or –extend displays other relevant information about the network.
-F or –FIB displays the fib.
-G or –groups displays the multi-broadcast feature group members list.
-h or Help online Help.
-I or –interfaces displays the Web interface information form.
-L or –listening displays the socket of the server in the monitor.
-M or –masquerade displays the spoofed network connection.
-N or –numeric uses the IP address directly, not through the domain name server.
-N or –netlink or –symbolic displays the symbolic connection name of the network hardware peripherals.
-O or –timers displays the timer.
-P or –programs shows the program identification code and program name that are using the socket.
-R or –route displays routing Table.
-S or –statistice displays the statistics of network work information.
-T or –tcp shows the connection status of the TCP transport protocol.
-U or –UDP shows the connection status of the UDP transport protocol.
-V or –verbose shows the instruction execution process.
-V or –version displays version information.
-W or –raw shows the connection status of the raw transport protocol.
-X or –unix the effect of this parameter is the same as specifying the "-A Unix" parameter.
– IP or –inet the effect of this parameter is the same as specifying the "-A inet" parameter.

Status Description:
LISTEN: Listening for connection requests from a remote TCP port
Syn-sent: Wait for a matching connection request after the connection request is sent (if there is a large number of such status packs, check if it is a trick)
Syn-received: After receiving and sending a connection request, wait for the other party to confirm the connection request (if there is a large number of this state, estimated to be flood attack)
Established: Represents an open connection
Fin-wait-1: Waiting for a remote TCP connection interrupt request, or confirmation of a previous connection interrupt request
Fin-wait-2: Waiting for connection interrupt request from remote TCP
Close-wait: Waiting for a connection interrupt request from a local user
CLOSING: Waiting for remote TCP to confirm connection interruption
Last-ack: Wait for acknowledgement of the original connection interrupt request to the remote TCP (not a good thing, this item appears, check whether it is attacked)
Time-wait: Wait enough time to ensure that the remote TCP receives a connection interrupt request acknowledgement
CLOSED: No connection status

eg
Netstat-apu display UDP port number usage
netstat-a | awk '/^tcp/{++s[$NF]} END {for (a in S) print A, S[a]} ' count the number of network connections in the machine
Netstat-nat | grep "192.168.120.20:16067" |awk ' {print$5} ' |awk-f: ' {print$4} ' |sort|uniq-c|sort-nr|head-20 view the highest IP address connected to a service port
NETSTAT-ANPT | grep ': 16064 ' Find the process running on the specified port
Ps
The PS command lists the current snapshots of those processes, which are those that are executing the PS command at the moment, and if you want to display process information dynamically, you can use the top command.

Command parameters:
-a displays all programs under the same terminal
-A Show All processes
C Displays the real name of the process
-N Reverse Selection
-e equals "-A"
e Display Environment variables
F show the relationship between programs
-H Display tree structure
R shows the process of the current terminal
T displays all programs for the current terminal
U specify all processes for the user
-au Show more detailed information
-aux Show all itineraries that contain other users
-C "command" lists the status of the specified command
–lines[rows] The number of rows displayed per page
–width[characters] The number of characters displayed per page
Help Display Help information
–version Display version display

There are 5 states of processes on Linux:
1. Running (running or waiting in the running queue)
2. Interrupt (dormant, blocked, waiting for a condition to form or receive a signal)
3. Non-interruptible (receive signal does not wake up and not run, process must wait until interrupt occurs)
4. Zombie (The process has been terminated, but the process descriptor exists until the parent process calls WAIT4 () after the system call is released)
5. Stop (process received Sigstop, SIGSTP, Sigtin, Sigtou signal after stop running run)

PS Tool identifies 5 status codes for the process:
D non-interruptible uninterruptible sleep (usually IO)
R run runnable (on run queue)
S Interrupt Sleeping
T stop traced or stopped
Z Zombie a defunct ("zombie") process

Output meaning:
F represents the flag of this program, 4 represents the user as Super user
S represents the status of this program (STAT), and the significance of each stat will be described in the text
The UID program is owned by the UID.
PID is the ID of this program!
PPID is the ID of its parent program
Percentage of resources used by the C CPU
PRI this is the abbreviation for priority (precedence order), which is described in detail later
NI This is a nice value, and in the next section we will continue to introduce
ADDR This is the kernel function, which points out the part of the program that is in memory. If it's a running program, it's usually "-"
SZ-Used memory size
Wchan whether the program is currently in operation, if it is-indicates that it is operating
TTY Login Terminal Location
Time used to consume the CPU.
What are the commands that CMD has issued?

eg
Ps-u root displays specified user information
PS-EF Displays all process information, along with the command line
PS aux lists all currently in-memory programs
Watch
The output of the command can be output to a standard output device, which is used for periodic execution of commands/timed execution commands

Command parameters:
-N or –interval watch defaults to run the program every 2 seconds, you can use-N or-interval to specify the time interval.
-D or –differences use the-D or –differences option Watch to highlight the changed area. The-d=cumulative option highlights the changes that have been made (regardless of the recent change).
The-T or-no-title will turn off the watch command at the top of the interval, command, output of the current time.
-h,–help Viewing Help Documents

eg
Watch-n 1-d ' pstree|grep http ' highlights changes in the number of HTTP links per second
Watch-d ' Ls-l|grep scf ' monitors changes to SCF ' files in the current directory
Watch-n ' Cat/proc/loadavg ' 10 seconds average load of one output system
Other Command referencevim mode switch
Other modes ==> Normal mode
Esc
Normal Mode ==> insert mode
I insert before the cursor I at the beginning of the line
A after the cursor inserts a at the end of the insertion
o Create a new row below the current line O on the current line
R replaces the current character R starting with the current character
Normal Mode ==> Command mode
:
Normal mode ==> visual mode
V, v,<ctrl+v>
Insert
I insert before the cursor
I Insert at the beginning of a line
A append after the cursor
A appends at the end of a line
o Open a new row in the next line where the cursor is positioned insert
O open a new row in the previous line at the cursor location insert
Find
Query environment settings
: Set Hlsearch Open highlighted text for lookup
: Set Nohlsearch to turn off highlighting of found text
: Nohlsearch turns off the currently highlighted results
: Set Incsearch open display find matching process
: Set Noincsearch turns off display find matching process
: Set ignorecase ignores case
: Set noignorecase exact Match case
: Set Nowrapscan Disable loop lookup mode
: Set Wrapscan Enable loop lookup mode
Command

/csdn down to find a string called CSDN
? Csdn up to find a string called CSDN
* and # Match the current word of the cursor, move the cursor to the next matching word (* is next, #是上一个)
n means to continue looking down the previous find operation (in conjunction with the above operation)
N means to continue looking up the previous find operation (in conjunction with the above operation)
/csdn\c ignoring case lookups, add \c after the string that asks for a lookup
:%s///gn counts the number of times the current pattern has been matched (actually called the substitute command, the flag bit n suppresses the normal substitution operation, and the replacement domain is not valid for any reason.) )
Replace
: [Range]s/from/to/[flags]

[Range]
Do not write default to the line where the cursor is located.
. The line where the cursor is located.
1 First line.
$ last row.
33 line 33rd.
The line where a mark A is located (previously marked with MA).
. +1 the line below the row where the cursor is currently located.
$-1 the penultimate line. (This shows that we can add a value to a row to get a relative line).
22,33 Line 22nd to 33rd.
1,$ the 1th line to the last row.
1,. Line 1th to the current row.
., $ the current line to the last row.
' A, ' B marks the line where a is located, and the row where Mark B is located.
% all rows (equivalent to 1,$).
? Chapter? Searches up from the current position and finds the row where the first chapter is located. (where chapter can be any string or regular expression.)
/chapter/searches down from its current location, and finds the row where the first chapter is located. (where chapter can be any string or regular expression.)
[Flags]
No substitution is made only for the first occurrence within the specified range.
G to replace all occurrences within the specified range. (g at the end of the command to replace each occurrence of the search string; G at the beginning of the command, indicating that all rows containing the search string in the body are replaced)
C Ask the user for confirmation before replacing.
e ignores errors in the execution process.
eg
: S/from/to/replaces the first from in the current row with a to. If the current row contains multiple from, only the first one is replaced.
: S/from/to/g replaces all the from in the current row with to.
: S/FROM/TO/GC replaces all the from in the current row with to, but asks the user to confirm the action before each replacement.
: 33s/from/to/g the replacement operation on line 33rd.
: $s/from/to/g the last line for the replace operation.
:%s/from/to/g replaces the contents of all rows.
: G/str1/s//str2/g (equals ": 1,$ s/str1/str2/g") replaces all occurrences of strings in the body with a string str2 str1
: G/str1/s/str2/str3/g replaces all strings in the body that appear in the STR1 line with the string Str3 str2
Copy and paste
Vim has 12 pasteboard (some versions larger than 12), 0-9,a, ", + etc., where" as the default pasteboard, + for the system Clipboard (: Reg View there is no + clipboard, no need to install gnome)

Y Copy the selected content (combined with the V,V command)
yy/y copying when moving forward
YW Copy the current word
2YY/Y2Y two lines
y$ Copy to end of line
y^ copying to the beginning of the line
"+yy Copy the current line to the system Clipboard
P lowercase p represents the post to the cursor (bottom).
The P-capital P represents the front (top) of the cursor.
"+p Paste system Clipboard contents
Jump
Ng/:n to Nth row
GG to the first line. (equivalent to 1G, or: 1)
G to the last row.
W to the beginning of the next word.
E to the end of the next word. (If the word is delimited by the blank character, you need to use uppercase E and W)
% match parentheses move, including (, {, [.] (Need to move the cursor to the parentheses first)
0 to Wardrobe
$ to the last character of the bank
^ The first non-blank character to the bank
G_ to the last position of the bank that is not a blank character.
FA to the next character of a in the bank, you can also fs to the next character for S.
T, to the first character before the bank comma. Commas can become other characters.
3fa finds the third occurrence of a in the current row.
F and T and F and T are just the opposite direction.
HJKL (←↓↑→) lower left upper right
<Ctrl+f> down one page
<Ctrl+d> down Half page
<Ctrl+b> up a page
<Ctrl+u> Half Page
Choose
V Selected character
V-Selected row
Ctrl + V Check block
Regional selection
VI "Check the contents of the current cursor"
VA "selects the contents of the current cursor" and contains "" "
V2A "Select the contents of the current cursor (#)" * "ro#d" * * ", including" "
Split screen
Split Create split screen (: Vsplit Create vertical split screen,: New blank document)
<Ctrl-w><dir> dir is the direction, can be a hjkl or ←↓↑→, which is used to switch the split screen.
<ctrl-w>+ (or <ctrl-w>-) increase in size
tab page
: Tabe/path/to/file.txt open a file in a new tab page
: tabnew Create a new tab page
: Tabs View tab list with ">" Display Current window, "+" to display modifiable buffers
: TABC Close the current tab page
: Tab split opens the file in the current buffer using the New tab page
: TABN switch to the next tab page
: TABP switch to the previous tab page
: Tabr[ewind] Go to the first tab page
: Tabf[irst] has the same effect as the previous command
More Command
D Delete Selection
X Cut the current character
R replaces the character of the cursor
U undo
Ctrl+r Revoke Revocation
GU selected contents to uppercase
Gu selected contents to lowercase
GD jumps to the location where the current word first appears, and can be used to find the local variable at the definition
DD Delete When moving forward
Ctrl+n,ctrl+p Auto-complete
J Merge Rows
"Jump to the place where the cursor was last docked, is two ' instead of a"
MX settings bookmark, x can only be a-Z 26 letters
' x jump to the bookmark ("'", back quote, 1 left key)
' x jump to the first character of the line where the bookmark is located ("'", quotation marks)
> Increase Indent, "x>" to increase indentation for the following x lines
< reduce indentation, "x<" means reducing indentation for the following x lines
:!< command > Temporarily switch to Shell execution command

Summary of Common Linux commands

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.