takeaway

This article does not cover all commands in detail, but only common usages and explanations. You can use –help to see help or just Google it.

Common commands

1. Find files

TXT Searches for the filename. TXT file in the/directory by name. . Find -name "*. XML recursively find all of the XML file. Find -name" *. XML "| xargs grep" hello world "recursive search for all the file content contained in the XML file grep - H hello world 'spring' *. XML search so some XML files with spring find. / - size 0 | xargs rm -f & delete file size zero ls -l | grep 'jar' search all the jar files in the current directory grep 'test' d* Displays lines containing test in all files starting with d. Grep 'test' aa bb cc Displays the line matching test in the aa, bb, cc file. Grep '[a-z]\{5\}' aa displays all lines containing strings with at least five consecutive lowercase characters per string.Copy the code

2. Check whether a program is running

Ps - ef | grep tomcat to see all process about tomcatCopy the code

3. Terminate the thread

Kill -9 19979 Terminates the process whose thread id is 19979Copy the code

4. View files, including hidden files

ls -al
Copy the code

5. Current working directory

pwd
Copy the code

6. Copy files

Cp source dest Copies filesCopy the code
Cp -r sourceFolder targetFolder Recursively copies the entire folderCopy the code
SCP sourecFile romoteUserName@remoteIp:remoteAddr Remote copyCopy the code

7. Create a directory

mkdir newfolder
Copy the code

8. Delete the directory

Rmdir deleteEmptyFolder Deletes an empty directoryCopy the code
Rm -rf deleteFile Deletes all contents in a directory recursivelyCopy the code

9. Move files

mv /temp/movefile /targetFolder
Copy the code

10, rename

mv oldNameFile newNameFile
Copy the code

11. Switch users

su -username
Copy the code

12. Modify file permissions

Chmod 777 file. Java Permission of file. Java - RWXRWXRWX, r indicates read, w indicates write, and x indicates executableCopy the code

Zip files

tar -czf test.tar.gz /test1 /test2
Copy the code

14. List the compressed files

tar -tzf test.tar.gz
Copy the code

Unzip the files

tar -xvzf test.tar.gz
Copy the code

16. Look at the first 10 lines of the file

head -n 10 example.txt
Copy the code

17. Look at the last 10 lines of the file

tail -n 10 example.txt
Copy the code

18. View the log type file

Tail -f exmaple.log This command automatically displays the new content, and the screen displays only 10 lines of content (configurable).Copy the code

19. Run commands as the super administrator

Sudo rm a. TXT Deletes files as an administratorCopy the code

20. Check the port usage

Netstat TLN | grep 8080 view port 8080Copy the code

21. Check which program the port belongs to

lsof -i :8080
Copy the code

22. Check the process

Ps aux | grep Java to check the Java processCopy the code
Ps aux Views all processesCopy the code

23. List the contents of a directory in a tree

tree a
Copy the code

24. File download

wget http://file.tgz
Copy the code
curl http://file.tgz
Copy the code

25. Network detection

ping www.just-ping.com
Copy the code

26. Remote login

ssh userName@ip
Copy the code

27. Print information

Echo $JAVA_HOME Prints the value of the Java Home environment variableCopy the code

The interview questions

28, Fetch lines 4 through 7 of the file aaa.txt

[root@localhost ~]# cat aaa.txt 1.aaa 2.bbbbbbb 3.ccccccccccccc 4.dddddddddddddddddddddd 5.eeeeeeeeeeeeeeeeee 6.ffffffffffffffffffffffffffffffffff 7.gggggggggggggggggggggg 8.hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh 9.iiiiiiiiiiiiiiiiiiii 10. JJJJJJJJJJJJJJJJJJJJJJJJJJ 11. KKK 12. LLLLLLLLLL/root @ localhost ~ # sed - n '4, 7 p' aaa. TXT 4. DDDDDDDDDDDDDDDDDDDDDD 5.eeeeeeeeeeeeeeeeee 6.ffffffffffffffffffffffffffffffffff 7.ggggggggggggggggggggggCopy the code

29, find the current directory TXT end files

[root@localhost ~]# ls
1.txt  2.txt  3.pdf  aaa.txt  anaconda-ks.cfg
[root@localhost ~]# find ./ -name "*.txt"
./aaa.txt
./1.txt
./2.txt
Copy the code

Find files in /usr that exceed 1M

/ root @ localhost ~ # find/usr -type f - size + 10240 k/usr/lib/locale/locale - archive/usr/lib64 / libicudata. So. 50.1.2Copy the code

Mysql master-slave replication principle

  • Update events (UPDATE, INSERT, DELETE) for the master db are written to the binlog. The master library creates a binlog dump thread and sends the contents of the binlog to the slave library. Start and initiate a connection from the library to the master library. After starting from the slave library, create an I/O thread that reads the binlog from the master library and writes it to the relay log. After starting from the slave library, create an SQL thread, read from the relay log, execute the read update event starting at Exec_Master_Log_Pos, and write the update to the SLAVE DB.

32. Vim works in several modes

  • Command mode. End of line mode, edit mode

33. Describe the DNS resolution process. Visit www.baidu.com for the resolution process

  • The local DNS cache is searched first to check whether the /etc/hosts file is forcibly resolved. If no resolution records are found on the DNS server specified in /etc/resolv.conf (The DNS server needs to be connected to the Internet. After finding resolution records on the DNS server, add a cache on the local DNS to complete DNS resolution

34, Explain the two modes of DNS query

  1. Recursive query

Recursive query is a query mode of the DNS server. In this mode, the DNS server must reply to the client with an accurate query result after receiving the client’s request. If the DNS server does not store the query DNS information locally, the server queries other servers and submits the returned query results to the client. 2. Iteratively querying the DNS server Another method is iterative query. The DNS server provides other DNS server addresses that can resolve the query request to the client. The client submits the request to the DNS server and loops until the result of the query is returned.

Describe forward and reverse proxies

  1. Forward agent

For example, if we visit foreign websites in China and cannot access them directly, we can send a request to the proxy server through a forward proxy server. The proxy server can access foreign websites, so that the proxy can fetch returned data from foreign websites and then return it to us, so that we can access. 2. Reverse proxy In actual operation, a reverse proxy uses a proxy server to receive Internet connection requests, forwards the requests to the Intranet server, and returns the results to the Internet client. At this point, the client simply accesses the proxy server without knowing how many servers are behind it.

Like 3 even support it!