This is the 8th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021
Search for processes by process name
How to use it?
/ / query process ps - ef | grep tomcatCopy the code
To clarify, ps(Process status) means to view a process.
Grep, which means search.
Then, mainly combines the pipe |, namely the front a output of the command, as behind a command input.
I’m going to focus a little bit more on the argument -ef.
Because it’s hard to remember parameters if you don’t know what they mean. Usually more may be completely by rote memorization, but if you know what it means, then there is no need to memorize.
So what does -ef mean? How about not? I can’t.
The function of E is the same as that of A. The function of A is to display all the information of the process. A knows the meaning of “all” at A glance, so there is no need to memorize it deliberately.
So why bring the A? Since the ps command doesn’t show that many fields by default, you might not find the corresponding process when you grep it — so you have to add -a. It’s better to use -a, because you don’t need to remember.
The f? Isn’t it already showing all the information? Why do I have to add f?
Obviously, because -a is all, it doesn’t actually show all of the fields, but if you add f, you can show more fields, such as the parent process ID, etc. — so f(full) is the real complete information.
Here’s the official explanation:
Search the logs for keywords
This is most commonly used in production environments, where logs are often searched by keyword to see problems.
How to do?
Grep Info.logCopy the code
Search for a single file. Search for multiple files.
Log error. LogCopy the code
The result is all matched rows.
What if I want to see the rows before and after the matched rows? Add the -c number.
grep -C 5 gzh test.txt
Copy the code
Indicates that, in addition to displaying the matching row, the top 5 rows and the bottom 5 rows of the matching row are also displayed.
Search and edit the contents of the file
How to search?
- vi test.txt
- Enter: / keyword.
Then press Enter to match the first one and highlight it.
- How do I match the next one or the last one?
Match the next press n.
Match a press N(i.e. Shift + N).
Search the contents of the screen
How to search?
CTRL + F, which may be slightly different on different operating systems.
When you’re done, the keywords will be highlighted.
Search history command
How to use it?
/ / search history command history | grep GZHCopy the code
The history command displays all history commands. But what if there are too many history commands and you can’t remember the one you typed? Search by keyword. The search content is the complete input of the history command, not just the history command itself.
The purpose of the search is to save yourself a half day of typing if a command is too long.
/ / search results ` ` ` gongzhihaodeMacBook - Pro: ~ gongzhihao $history | grep GZH 51 grep gongzhihao jmeter. Log 56 CD GZH 61 CD GZH 77 locate gzh 82 cd gzh 117 grep gzh test2.txt 126 history | grep gzh gongzhihaodeMacBook-Pro:~ gongzhihao$ ```Copy the code