Master the 23 common Linux commands and get a 30% increase in salary.

Source: Internet
Author: User
Tags solr cpu usage disk usage

As a working years of Linux ops old driver, summed up the common use of Linux command line some of the usage, I hope you have something to gain.

1. Search

In VI and VIM if you open a large file, it is not easy to find the corresponding content, you can use your own search keywords to search and locate:

In the VI and VIM interface input: "/" (backslash), then there will be an input box for you to enter, when you enter the keyword in the file will be displayed in the form of highlighting, and then press ENTER to determine the location of the current highlight, if not you are looking for, you can press: "N", Look for the next input keyword content.

2. Vim Recovery and garbled problem

(1) in VI and vim if accidentally accidentally deleted something, want to recover what to do?

To exit the edit state first, press the ESC key, and then press U to undo the previous modified content.

(2) When using VI or VIM to open a file, if some places appear some special symbols or garbled, you can try by the following command:

Vim-b mytest.php (where-B is typically used to view the corresponding binary file)

3. Pipe command, that is, vertical bar--' | '

The above means: give the query out to the command after the pipeline decoration and then show it

Example: Cat Install.log | More (meaning that the content of a screen will not fit in the form of paging)

Ls-l/etc | More

If you want to see the contents of a page, you can view it by: Shift + PageUp

Piping with grep (filter) can be used for a very good combination of example:

Cat-n Hello.txt | grep "Hello" (View the contents of the Hello.txt file and filter out the content with Hello),-n indicates the contents of the first few lines displayed

4. Find search file or directory

Find/home-name hello* (Find the file name or directory for Hello in the home directory)

Find/-name h?m* (the second character is arbitrary at the beginning of the search with the directory, and the third is m, followed by any character)

Find/-size +1000000k (indicates that files larger than 1000000K are queried in the root directory)

5 String Substitution command

: S/well/good/replaces the current line with the first well being a good

: S/well/good/g replaces the current line all well is good

: N, $s/well/good/replaces the first well of each row in the beginning of the nth row to the last row good

: N, $s/well/good/g replace the nth line to the last row, and all well is good for each row

N is a number, if N is., indicating the beginning of the current line to the last row

:%s/well/good/(equivalent to: g/well/s//good/) replaces the first well of each row as good

:%s/well/good/g (equivalent to: g/well/s//good/g) replaces all the well in each row as good

Special symbol Escape: You can use # as a delimiter, at which time the middle appears/does not act as a delimiter

: s#well/#good/# Replace the current row the first well/is good/

:%s#/usr/bin#/bin#g can change all the paths in the file/usr/bin to/bin

6. REDIRECT Command

Ls-l/etc/Hope

Ls-l/etc >/home/myback.txt (overwrite redirect) overlay the displayed results in/home/myback.txt

Ls-l/etc >>/home/myback.txt (append redirect) append the displayed results to the/home/myback.txt

7. Delete multiple lines

Delete the multiline steps as follows:

1. First display the corresponding number of rows so that you can know how to delete from line to line

: Set Nu

2. Press ESC to exit, and at the command line enter: 190,6233d (i.e. [190, 6233] are removed)

If you want to condition the entire file contents, run the following command directly:

Empty file contents:> Log.txt

8. Row position Positioning

Navigate directly to the last line:

Press the ESC key to exit, and at the command line, enter: G

Navigate directly to the first line:

Press the ESC key to exit, and on the command line, enter: 1 G

Navigate directly to a line: (line 17th)

Press the ESC key to exit, and on the command line, enter: + G

9. Copy one or more rows

<1. Copy a row

YY copy when moving forward

P Paste

<2. Copy Multiple lines

7yy copying 7 rows starting from the current line

P Paste

View Python versions in Linux

Python-v

Or

Python--version

A. grep usage

<1. Displays the following n rows of the match (after)

Grep-a N

<2. Displays the first n rows of the match (before)

Grep-b N

<3. Displays the front and back n rows of the match (context)

Grep-c N

<4. Ignore case

Grep-i Str

Description of the LL or LS display

Ll-ht (H will automatically convert the size according to the standard format: 456m,1.2g, etc., t means the display content is in reverse chronological order)

Application Case:

Empty the August log file:

Rm-rf ' Ll-ht | awk '/8 months/{PRINT6,6,NF} ' | awk ' {print $NF} '

Description: awk '/pattern/action '--and awk '/8 month/{PRINT6,6,NF} ', showing only the contents of line sixth and the last row and preserving only the August list content display.

The display of file colors in LS means:

1. Blue---Directory

2. Green---executable file

3. Red--Compress files

4. Light blue--linked files

5. Gray--Other files

13. See which process is taking up a file

Lsof file name

650) this.width=650; "title=" "src=" Http://s5.51cto.com/wyfs02/M01/9B/2E/wKioL1lfIsCxDGWTAAAIwRwfwP0951.png-wh_ 651x-s_2265151125.png "border=" 0 "/>

14. Create a user and view the current user

Useradd Redis passwd Redis

If it is an Ubuntu system, you need to use the following command:

Useradd openstack-m-s/bin/bash userdel-r OpenStack

View user groups and users that exist on the current system

/etc/group file contains all groups

All user names exist for/etc/shadow and/etc/passwd systems

15. Common view file size with Linux system commands

To view memory usage: free-m (M is mb,g GB)

650) this.width=650; "title=" "src=" Http://s4.51cto.com/wyfs02/M00/9B/2E/wKiom1lfItXRb1-GAAAJOyIbd0c265.png " border= "0"/>

View corresponding disk usage: DF-LH

650) this.width=650; "title=" "src=" Http://s1.51cto.com/wyfs02/M00/9B/2E/wKioL1lfIt-w4FN0AAAMCFE6Uew925.png " border= "0"/>

To view the corresponding CPU usage: Cat/proc/cpuinfo

There will be 32 roughly the same content (the subscript is starting from 0), which means that the server is a 8-core operating system

650) this.width=650; "title=" "src=" Http://s3.51cto.com/wyfs02/M01/9B/2E/wKiom1lfIuqSzRw3AAEjv9tDnu4890.png " border= "0"/>

Or have a better command:

Cat/proc/cpuinfo | grep "Model Name" | Head-1 (show only one line for the CPU model and other information)

Cat/proc/cpuinfo | grep "model name" (a few lines are displayed on the system with several cores)

Cat/proc/cpuinfo | grep "Model Name" | Wc-l (Count the total number of cores)

View the corresponding Server version current operating system release information: Cat/etc/issue or Cat/etc/redhat-release

650) this.width=650; "title=" "src=" Http://s3.51cto.com/wyfs02/M02/9B/2E/wKiom1lfIvmRyqJFAAAGCaGui_Q036.png " border= "0"/>

View the more underlying version information: Cat/proc/version (for example: The actual CentOS root is rethat, this command will show the version of the rethat used)

650) this.width=650; "title=" "src=" Http://s1.51cto.com/wyfs02/M00/9B/2E/wKioL1lfIwSwDM00AABBYGwUOh8951.png " border= "0"/>

If you want to see the amount of space currently occupied by a folder:

Du-h node (cd/data/solr-4.8.0/)

650) this.width=650; "title=" "src=" Http://s4.51cto.com/wyfs02/M01/9B/2E/wKioL1lfIxGiVBxEAAASzeM6U9g204.png " border= "0"/>

If you want to see the size of all the files in the current directory

DU-SH * (CD/)

650) this.width=650; "title=" "src=" Http://s1.51cto.com/wyfs02/M02/9B/2E/wKioL1lfIxqyXt3QAAAFa8Ap5TI600.png " border= "0"/>

16. View memory Status

<1. JSTAT-GC PID can see the corresponding memory size, usage status and GC processing situation

<2. JMAP-HEAP [PID] View memory distribution

<3. Jstat-gcutil [PID] 1000 GC case for output java process every 1s

17. Modify the permissions of the folder and its contents

Chown-r Solr:solr/home/solr/lib

This means that the user-owned permissions of the/home/solr/lib folder and its contents are modified to the permissions of the SOLR user

18. View the number of connections for a port link state

Netstat-nlap | Grep-i EST | Grep-i 6379 | awk ' {print $4} ' Netstat-nlap | Grep-i EST | Grep-i 1121 | Wc-l

Usually use summary, use this command if you do not remember what the following parameters, then directly remember as:-nlap, most of the situation can meet our needs

Netstat common parameters are as follows:

-A (All) displays all options and does not show listen related by default

-T (TCP) displays only TCP-related options

-U (UDP) displays only UDP-related options

-N refuses to display aliases, showing all numbers converted to numbers.

-l list only service status in Listen (listening)

-P Displays the program name that establishes the associated link

-R display routing information, routing table

-e display extended information, such as UID, etc.

-S statistics according to each protocol

-C executes the netstat command every other fixed time.

Hint: The status of listen and listening can only be seen with-a or-l

Grep-i (i means ignoring case)

awk ' {print $4} ' (means only the 4th column is printed)

Grep-i EST (est means: established, which is the port that only shows established as the connection state)

The final result of the grep command is marked with red, that is, the last grep is: Grep-i 6379, then the printed result of which 6379 is red, the result is as follows:

650) this.width=650; "title=" "src=" Http://s4.51cto.com/wyfs02/M01/9B/2E/wKioL1lfIzCy-2EDAAFlUMCw87I198.png " border= "0"/>

19. Synchronizing the server time

Ntpdate pool.ntp.org

Enable this command for timed script execution, as follows:

1 */2 * * * ntpdate pool.ntp.org

20. Do not allow SSH login how to configure

To modify the Vim/etc/sysconfig/sshd_config file, add a line: Allowusers SOLR, as follows:

650) this.width=650; "title=" "src=" Http://s2.51cto.com/wyfs02/M02/9B/2E/wKiom1lfI0PyH4-0AAAPWgmktPE270.png " border= "0"/>

Make it effective run the following command:

Service sshd Reload

General system-level configuration summary:

1. Restrict login:/etc/ssh/sshd_config need to restart after modification: service sshd restart

2. User Configuration:/etc/passwd

3. Sudo permissions:/etc/sudoers

21. Common JDK System environment variable configuration

1.java_home=/usr/java/jdk1.7.0_55

2.classpath=.: $JAVA _home/lib.tools.jar

3.path= $JAVA _home/bin: $PATH

4.exportjava_home CLASSPATH PATH

22. View the version of Redis/tomcat

REDIS-CLI Info | grep ' Redis_version '

The Tomcat version needs to go to the Bin/folder in the installation directory:

./version.sh or SH version.sh

23. How to see if the Linux firewall blocks port 80

1IPTABLES-VNL |grep ": 80"


This article is from the "high-tech Library" blog, please be sure to keep this source http://gaopengju.blog.51cto.com/12830710/1947386

Master the 23 common Linux commands and get a 30% increase in salary.

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.