19 Linux Commands and Tricks That Will Help You Raise the Salary.

CCNA 200-301

CCNA 200-301

CCNP Enterprise

CCNP Enterprise

CCNP Security

CCNP Security

CCIE Enterprise Lab

CCIE Enterprise Lab

CCIE Security Lab

CCIE Security Lab

CCNP Service Provider

CCNP Service Provider

CCNP Data Center

CCNP Data Center

CCNP Collaboration

CCNP Collaboration

CCIE DC Lab

CCIE DC Lab

ic_r
ic_l
19 Linux Commands and Tricks That Will Help You Raise the Salary.
images

From SPOTO, you can find everything you need to prepare for your Linux certification.

Operation and Maintenance Engineer (Operations) is also called Operational Development Engineer (Devops) in China and SRE (Site Reliability Engineering) in foreign countries. Responsible for maintaining and ensuring high availability of the entire service while continuously optimizing the system architecture, improving deployment efficiency, optimizing resource utilization and improving overall ROI.

As a long-time Linux operation and maintenance driver, I have summarized some common usages of the Linux command line, and I hope to gain something for you.

Search

If you open a large file in vi and vim, it is not easy to find the corresponding content, you can use the built-in search keyword to search and locate:

In the vi and vim interface, type: "/" (backslash), after which an input box will appear for you to input. When the keyword you enter exists in the file, it will be highlighted, then press back. The car is determined to be positioned to the current highlighted position. If it is not what you are looking for, you can press: "n" to find the content of the next input keyword.

2. vim recovery and garbled problems

(1) What if I accidentally delete something in vi and vim and want to recover?

To exit the editing state first, press the Esc key, then press u to undo the previous modified content.

(2) When opening a file with vi or vim, if some special symbols or garbled characters appear in some places, you can try it by the following command:

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

3. Pipeline command, ie vertical bar --> '|'

The above meaning is: the contents of the query are given to the command behind the pipe to decorate and then displayed.

For example: cat install.log | more (more means to display the contents of a screen in a paginated form)

Ls -l /etc | more

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

Pipes combined with grep (filtering) can achieve a very useful combination such as:

Cat -n hello.txt | grep "hello" (view the contents of the hello.txt file and filter out the contents with hello), -n indicates the contents of the first few lines

4. find search for files or directories

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

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

Find / -size +1000000k (meaning that the file is larger than 1000000K in the root directory)

5 string replacement command

:s/well/good/ replace the current line first well is good

:s/well/good/g replace the current line all wells are good

:n,$s/well/good/ Replace the first well of each line in the beginning of the nth line to the last line is good

:n,$s/well/good/g Replace the nth line from the beginning of the line to the last line.

n is a number, if n is ., it means starting from the current line to the last line

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

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

Special symbol escaping: You can use # as a separator, and / in the middle will not act as a separator

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

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

6. Redirect command

Ls -l /etc/ hope

Ls -l /etc > /home/myback.txt (overwrite redirect) overwrites the displayed result to /home/myback.txt

Ls -l /etc >> /home/myback.txt (additional redirection) appends the displayed result to /home/myback.txt

7. Delete multiple lines

The steps to delete multiple lines are as follows:

1. First, you need to display the corresponding number of lines so that you can delete from the first few lines to the first few lines.

: set nu

2. Press Esc to exit. On the command line, type: 190, 6233d (ie [190, 6233] are deleted)

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

Empty file contents: > log.txt

8. Position positioning

Directly navigate to the last line:

Press Esc to exit and type: G on the command line

Directly navigate to the first line:

Press Esc to exit and type in the command line: 1 G

Directly locate a line: (line 17)

Press Esc to exit and type in the command line: 17 G

9. Copy one or more lines

<1. Copy a line

Yy copy the current line

p paste

<2. Copy multiple lines

7yy copy 7 lines from the current line

p paste

10. View the version of python in Linux

Python -V

or

Python --version

11. Usage of grep

<1. Display the matching n lines (after)

Grep -A n

<2. Display the first n lines of the match (before)

Grep -B n

<3. Display matching before and after n lines (context)

Grep -C n

<4. Ignore case

Grep -i str

12. ll or ls display instructions

Ll -ht (h will automatically convert the size according to the standard format: 456M, 1.2G, etc., t means that the display content is arranged in reverse chronological order)

Applications:

Clear the August log file:

Rm -rf `ll -ht | awk '/August / {print6,6,NF}' | awk '{print $NF}'`

Description: awk '/pattern/action'--> awk '/August/{print6,6,NF}', only displays the contents of the sixth and last lines and only keeps the contents of the list for August.

The display of the file color in ls represents the meaning:

1. blue --> directory

2. Green --> Executable

3. Red --> Compressed file

4. Light blue --> link file

5. Gray --> Other files

13. Create users and view current users

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 the user groups and users that exist in the current system.

/etc/group file contains all groups

All usernames in the /etc/shadow and /etc/passwd systems

14. View memory conditions

<1. jstat -gc pid can see the corresponding memory size, usage status and GC processing

<2. jmap -heap [pid] View memory distribution

<3. jstat -gcutil [pid] 1000 Output gc of java process every 1s

17. Permission to modify the contents of the folder and its contents

Chown -R solr:solr /home/solr/lib

This means modifying the permissions of the user in the /home/solr/lib folder and its contents to the permissions of the solr user.

15. View the number of connections for a port link status

Netstat -nlap | grep -i est | grep -i 6379 | awk '{print $4}'

Netstat -nlap | grep -i est | grep -i 1121 | wc -l

Usually use the summary, if you can't remember what the following parameters are, just remember: -nlap, most of the time can meet our needs.

16. Synchronize server time

Ntpdate pool.ntp.org

Enable this command as a timed script execution as follows:

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

17. 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

18. View the Redis/Tomcat version

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

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

1iptables -vnL |grep":80 "

Return to the content description to open, if there is no return content, it means blocking.