Common Linux commands at work

Source: Internet
Author: User

1. Copying folders from other machines

Format: Scp-r folder name User name @ machine Name:/path
Example: Scp-r search [Email protected]:/home/work/
2. See which program is using a specific port

Format: Netstat-nap | grep Port number
Example: Netstat-nap | grep 8080
3. Real-time monitoring of log file contents

Format: tail-f log file name
Example: Tail-f ui.log
Description: This displays the last ten lines of the Ui.log file. The tail command continues to display lines that are added to the Ui.log file. The display will continue until you press the CTRL-C key sequence to stop
4. View the processes owned by the specified user

Format: Pstree User ID
Example: Pstree work
Description: Shows the inheritance relationships between the processes that the work user is running, listed in a tree-like structure
5. View disk space usage

Format: df-h
6. Find the line in a file where the specified string appears

Format: grep Specifies the string file name
Example: grep drama summer Taste Ui.log
Description: Find the line in the log file Ui.log that contains "TV drama Summer Flavor"
7. View Memory usage

Format: Free
8. View the native system kernel

Format: uname-a
9. View the file/folder size under the current path

Format: DU-HS file name/folder name
10. Change to the identity of other users

Format: SU user account
Example: SU work
11. Remote Login

Format: SSH user name @ machine name
Example: SSH [email protected]
12. Run the command without hanging off

Format: Nohup Command &
Example: Nohup./build_index.sh-d. /newdbi/&
13. View the number of rows in a file

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

Format: Vimdiff file 1 File 2
Example: Vimdiff 1.txt 2.txt
15. Kill the Process

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

Not a special reason.-9
16. In the SecureCRT file to the local SECURECRT installation directory download directory

Format: SZ-E file name
Example: Sz 1.txt
17. Pass the native file to the current directory of the current machine in SECURECRT

Format: RZ-E
18.Vi Text Editor

Format: vi [options] File name
Parameters:
+n editing a file starting from Nth line
+/exp the first line of exp from a matching string in a file start editing
There are two main types of operations in VI: Command mode and insert mode, which convert between modes:
i/i
Command mode insert mode
Esc
Some important commands in the VI command mode:
U Undo last Edit Action
: q! Discard the contents of the buffer and launch VI
: Wq saves the contents of the buffer and launches VI
Example: VI txt1
More useful commands in VI:
cw Used to delete a line from the beginning of a word to the end of the section and into the editing state.
For example, there is a line in a file: Aabbccddeeffgg
I want to delete the EEFFGG, then I can in the non-editing state, the position of the cursor at the first "E", using the CW command, then, the EEFFGG is deleted, and can start editing.
Set Nu. Used to display line numbers. In the non-editable state, use ": Set Nu" to enter.
0. This command is used to move to the beginning of the line in non-editable state.
$ This command is used to move to the end of a line in a non-editable state.
~ Uppercase and lowercase conversions. In the non-editable state, move the cursor to a character, using the ~ command, then lowercase letters will be capitalized, uppercase letters will become lowercase.
P. The system retains the last 9 rows that were deleted in the buffer. Therefore, if you want to restore the last deleted row, use the "1p" command in a non-editable state. Use the "2p" command in a non-editable state if you want to restore the 2nd deleted row.
commands to scroll the screen:
^F Scroll forward one screen
^B Scroll Backward one screen
^d rolling forward half screen
^u rolling back half screen
Move inside the screen
H move to start point--First line of screen
M moves to the middle row of the screen
L move to the last line of the screen
NH moves to line n below the first line of the screen
NL moves to line n above the end of the screen
Search
N Duplicate Search
N Reverse Duplicate Search
/Enter forward repeat search
? Return backward Repeat Search
Comment out the 第1-10 line in the script: use: ": 1,10s/^/#".

19. View File Types

Format: File file name
20. Text Extraction

Format: awk [-F Domain Separator] ' command ' input file name
Description: Awk is used to extract information from text files and strings, and for information to be obtained, the text must be formatted, meaning that the domain separator is used to divide the extracted domain, and the delimiter can make any character. Commands is composed of two parts: the mode and the action, the mode part determines when the action statement is triggered, the pattern can make any conditional statement or compound statement or regular expression, the actual action in the parentheses {} named, the action is mostly used to print, if do not specify the action, awk will print out all the browsing out of the record.
When Awk executes, its browsed domain is marked as 1, 2, 3 ... . . N0 for all domains
Some of the built-in variables for awk:
NF browsing record number of fields
NR number of records read
Fiilename the file name that awk browses
Example:
awk ' END {print NR} ' Grade.txt
awk ' {if ( 4== "Yellow" | | 4 /BRoWN/)PRINT 0} ' Grade.txt
21. Non-interactive text flow editor

Format: sed [options] ' command ' Enter file name
Parameters:
-N Do not print, SED does not write edit line to standard output, default is to print all lines
-c The next command is to edit the command and include this option when using multiple edits. If only one sed command is used,
This option is useless, but it does not matter if you specify it.
-F Use this option if you are invoking the SED script file. This option informs Sed that a script file supports all SED commands, for example: Sed-f myscript.sed input_file, where myscript.sed is the file that supports the SED command.
Example:
Sed–n ' 2p ' quota.txt print the second line of text
Sed–n '/neave/' P quota.txt matches the word Neave and prints this line
Sed ' 1d ' quota.txt delete the first line of text
22. Classify the records in a file

Format: Sort [option]–o output file name [other options] +pos1 +pos2 input file name
Parameters:
-C test file is categorized
-m merge two categorical files
-U Delete all replicated rows
-o stores the output file name of the sort result
Other parameters are:
-B ignores the first space when using a field for classification.
-n Specifies that the classification is a numeric classification on the domain.
-t domain delimiter; separate fields with non-whitespace or T-a-B keys.
-R to sort order or compare inverse.
+n n is the domain number. Use this field number to start the classification.
n n is the domain number. This field is ignored when classifying comparisons and is generally used with + N.
Pos1,pos2 passed to M,n. M is the domain number, and n is the number of characters starting to be classified, for example, 4,6 is classified as the 5th field, starting with the 7th character.
Example: sort-t: +2n video.txt with ":" As the domain separator, sorted by the third field number Video.txt
23. Remove duplicate lines of text files

Format: uniq [options] Input file [output file]
Parameters:
-U displays only non-repeating rows.
-D displays only duplicate rows, with each repeating row showing only one row
-C Prints the number of occurrences of each repeating row.
-F N is a number, and the first n fields are ignored. Some systems do not recognize the-f option, at which point the substitution is used-N.
Example: Uniq–n2 parts.txt
24. Connection of two text files

Format: Join [options] File 1 file 2
Note: Join is used to connect lines from two text files, two input files must have been divided into classes, and there are elements in each file associated with another file, and because of this relationship, join connects two files together.
Parameters:
-an N is a number that displays unmatched rows from file n when connected. For example,-a 1 shows unmatched rows for the first file, and-a 2 shows 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 file 1 third domain, each n,m must be separated by commas, such as 1. 3,2. 1.
-j N m n is the file number and M is the domain number. Use a different domain for the connection domain.
-T Domain delimiter. The field delimiter used to set a non-space or T-B key. For example, specify a colon to do the field delimiter-T:
Example: Join–o 1.1,2.2 names.txt town.txt
25. Cut columns or fields from a text file

Format: Cut [options] file name
Parameters:
The-c list specifies the number of cut characters.
The-f field specifies the number of clipping fields.
-d Specifies a field delimiter that differs from the Space and tab keys.
-C is used to specify the clipping range as follows:
-C 1,5-7 cuts the 1th character, then the 5th to the 7th character.
The-f format is the same as-C.
-F 1,5 Clipping 1th field, 5th field.
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 first need to categorize it and make sure that two files are the same number of rows. Paste will put different file line information on one line. By default, when you paste a connection, separate text from the new line is separated by a space or Tab key, which becomes a domain delimiter unless you specify the-D option.
Parameters:
-d Specifies a field delimiter that differs from the space or t a B key. For example, use @ to separate the fields, using-D @.
-S merges each file into rows instead of by line.
Example: Paste–d:pas2 pas1 using a colon as a separator
27. Splitting a large file

Format: Split [options] Enter file name output filename prefix
Parameter:-a specifies the length of the suffix (default is 2)
-B byte size per output file
-l number of rows per output file
Example: Split–l bigfile.txt outfile

Common Linux commands at work

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.