Common linux commands

Source: Internet
Author: User

Common linux commands

1. Copy folders from other machines

Format: scp-r folder name username @ machine name:/path
Example: scp-r search work@zjm-testing-ps23.zjm.baidu.com:/home/work/
2. Check which program is using a specific port

Format: netstat-nap | grep port number
Example: netstat-nap | grep 8080
3. Monitor log file content in real time

Format: tail-f Log File Name
Example: tail-f ui. log
Note: This shows the last 10 lines of the ui. log file. The tail command continues to display the rows added to the ui. log file. The display continues until you press Ctrl-C to stop.
4. View processes owned by a specified user

Format: pstree user ID
Example: pstree work
Description: displays the inheritance relationships between running processes of the work user, which are listed in a tree structure.
5. view disk space usage

Format: df-h
6. Search for rows with specified strings in a file

Format: grep specifies the string file name
Example: grep TV series xiatian flavor ui. log
(Find the line that contains "Summer taste of TV series" in the log file ui. log)
7. view memory usage

Format: free
8. view the kernel of the Local System

Format: uname-
9. view the file/folder size in the current path

Format: du-hs file name/folder name
10. change to another user's identity

Format: su User Account
Example: su work
11. Remote Login

Format: ssh username @ machine name
Example: ssh rd @ build01
12. Run the command without hanging up

Format: nohup command &
Example: nohup./build_index.sh-d ../newdbi /&
13. view the number of objects

Format: wc-l file name
Example: wc-l as. conf
14. Compare the differences between the two files

Format: vimdiff file 1 file 2
Example: vimdiff 1.txt 2.txt
15. Killing Processes

Format: killall-9 process name
Example: killall-9 bs. se

Not for special reasons-9
16. Upload the file to the download directory of the local SecureCRT installation directory in SecureCRT.

Format: sz-e file name
Example: sz 1.txt
17. Pass the local file to the current directory of the current machine in SecureCRT

Format: rz-e
18. Vi Text Editor

Format: vi [Option] File Name
Parameters:
+ N edit the file from line n
+/Exp: edit the first line matching the string exp in the file.
There are two main types of operations in Vi: Command mode and insert mode. The conversion between modes is as follows:
I/I
Command mode insert mode
ESC
Important commands in Vi command mode:
U cancels the last edit action
: Q! Discard the buffer content and release vi
: Wq saves the buffer content and releases vi
Example: vi txt1
More useful commands in Vi:
Cw. Deletes the part from the beginning to the end of a word in a row and enters the editing status.
For example, a file contains the following line: aabbccddeeffgg
If I want to delete eeffgg, I can place the cursor position in the first "e" without editing and use the cw command, eeffgg is deleted and can be edited.
Set nu. Displays the row number. In the non-editing status, use ": set nu" and press Enter.
0. This command is used to move to the beginning of a line in the unedited state.
$. This command is used to move to the end of a non-edit row.
~. Case-sensitive conversion. In the non-editing status, move the cursor to a character and use ~ Command, the lower-case letters will be converted to upper-case letters, and the upper-case letters will be changed to lower-case letters.
P. The system retains the last nine deleted rows in the buffer zone. Therefore, if you want to restore the last row to be deleted, use the "1p" command in non-editing state. If you want to restore the last 2nd deleted rows, use the "" 2p "command in non-editing status.
Scroll screen command:
^ F scroll forward one screen
^ B scroll back to a screen
^ D scroll forward half screen
^ U scroll back to the half screen
Move inside the screen
H move to the starting point-the first line of the screen
M moves to the middle line of the screen
L move to the last line of the screen
NH moves to line n below the first line of the screen
Line n at the end of the nL Screen
Search
N repeated searches in the Same Direction
N reverse repeated search
/Press enter to repeatedly search forward
? Press enter to repeat the search
Comment out line 1-10 in the script: ": s/^ /#".

19. view the file type

Format: file Name
20. Text Extraction

Format: awk [-F domain delimiter] 'COMMAND 'input file name
Note: awk is used to extract information from text files and strings. To obtain information, the text must be formatted, meaning that the extraction domain is divided by the domain delimiter. The delimiter can be any character. Commands consists of the mode and action. The mode determines when an Action Statement is triggered. The mode enables any conditional statement, composite statement, or regular expression. The actual action is specified in parentheses, most of the actions are used for printing. If no action is specified, awk will print all the browsing records.
When awk is executed, Its browsing domain is marked 1, 2, 3 ..... N, 0 indicates all domains.
Some built-in variables of awk:
Number of NF browsing records
Number of records read by NR
FIILENAME awk browsed file name
Example:
Awk 'end {print NR} 'grade.txt
Awk '{if (4 = "Yellow" | 4/Brown/) print 0} 'grade.txt
21. non-interactive text stream Editor

Format: sed [Option] 'COMMAND 'input file name
Parameters:
-N: No printing; sed: No editing row to standard output. All rows are printed by default.
-C: The next command is the edit command. This option is added when multiple edits are used. If only one sed command is used,
This option is useless, but it does not matter if it is specified.
-F if the sed script file is being called, use this option. This option notifies sed that a script file supports all sed commands, for example, sed-f myscript. sed input_file. Here myscript. sed is a file that supports sed commands.
Example:
Sed-n '2p' quota.txt prints the second line of text
Sed-n'/Neave/'P quota.txt match the word Neave and print this line
Sed '1d 'quota.txt deletes the first line of text
22. classify records in files

Format: sort [Option]-o output file name [other options] + pos1 + pos2 input file name
Parameters:
-C: whether the test file has been classified
-M: merge two classification files.
-U: delete all duplicate rows.
-O stores the output file name of the sort result
Other parameters include:
-When B uses a domain for classification, the first space is ignored.
-N indicates that the category is a digital classification in the domain.
-T domain separator; use non-spaces or t a B key to separate fields.
-R calculates the inverse of the classification order or comparison.
+ N is the domain number. Use this domain number to start classification.
N is the domain number. This field is ignored during classification comparison. It is generally used with + n.
Pos1 and pos2 are passed to m and n. M is the domain number, and n is the number of characters that start to be classified. For example, 4 or 6 means that the data is classified by 5th domains and starts from 7th characters.
Example: sort-t: + 2n video.txt, which is separated by the ": operator" field and is classified by the third field.
23. Remove duplicate lines of text files

Format: uniq [Option] input file [output file]
Parameters:
-U only displays non-duplicate rows.
-D: only duplicate data rows are displayed. Only one row is displayed for each duplicate row.
-C: print the number of times each duplicate row appears.
-F n is a number, and the first n fields are ignored. Some systems do not recognize the-f option. In this case, use-n instead.
Example: uniq-n2 parts.txt
24. connect two text files

Format: join [Option] File 1 file 2
Note: join is used to link rows from two text files. The two input files must have been divided into classes. Each file has some elements related to another file. Due to this relationship, join connects two files.
Parameters:
-An n is a number used to display unmatched rows from file n during connection. For example,-a 1 shows the unmatched rows of the first file, and-a 2 shows the unmatched rows from the second file.
-O n. m n is the file number, and m is the domain number. 1. 3 indicates that only the third domain of file 1 is displayed. Each n and m must be separated by commas (,), for example, 1. 3. 2. 1.
-J n m n is the file number, and m is the domain number. Use other domains as the connection domains.
-T domain separator. It is used to set the domain Separator of non-space or t a B key. For example, specifying the colon as the domain separator-t:
Example: join-o 1.1, 2.2 names.txt town.txt
25. Cut columns or fields from text files

Format: cut [Option] File Name
Parameters:
-C list specifies the number of characters to cut.
-F field specifies the number of cut fields.
-D specifies the domain separator different from the space and tab key.
-C is used to specify the cut range, as shown below:
-C 1st-7 Cut 5th characters, followed by 7th to characters.
-F format is the same as-c format.
-F 1st cut 5th domain, domain.
Example: cut-d:-f3 pers
26. paste the two text files together

Format: paste [options] file1 file2
Note: When pasting data from two different sources, you must first classify the data and ensure that the two files have the same number of lines. Paste places the information of different lines in one row. By default, paste is used to separate different texts in a new line with spaces or tabs. Unless the-d option is specified, it will become a domain separator.
Parameters:
-D specifies the domain separator different from space or t a B key. For example, use @ to separate domains and use-d @.
-S merges each file into rows instead of by row.
Example: paste-d: pas2 pas1 delimiter using colons
27. Split large files

Format: split [Option] prefix of input file name output file name
Parameter:-a specifies the suffix length (2 by default)
-B size of each output file in bytes
-L number of lines per output file
Example: split-l 1000 bigfile.txt outfile

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.