In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to use the find command in cmd, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
I am so dependent on findstr that when I explain the find command to you, I have to honestly type find /? in the cmd window. This command, and then press enter heavily.
Find /? The result of the execution was very fast, and all the help information came out in a flash. Compared with more than 10 switches in the findstr command, find has only five switches, which is negligible.
The basic format of the find command is as follows: find "string to find" the file to find, here, "string to find" is essential, and quotation marks are necessary. For example: find "bathome" d:\ test.txt, which means to look for all lines containing the string bathome in the text file test.txt under the root of the D disk.
There will be two scenarios for the results of find:
1. When the file contains the string to be found, the entire line of the location of the string will be returned in the following format: the first line is "- × × ×" (× × × represents the name of the file to be looked up, excluding the pair of quotation marks). The whole line containing the string appears at the beginning of the second line.
2. When the string to be found does not appear in the file, the result of find only returns the line "- × × ×" (× × × represents the name of the file to be looked up, excluding quotation mark pairs).
When looking for a specified string, some situations need to be case-sensitive, others do not care about case, how to achieve these requirements?
Very simple, in find, add or cancel the / I switch, the specific usage is: find / I "Abc" test.txt means case-insensitive, text content contains Abc, abc, ABC and so on; find "Abc" test.txt is strictly case-sensitive and can only match Abc, not abc, ABC and other characters.
Sometimes, our requirement is not to find a string, but to detect which lines do not contain a particular string. In this case, we can use the switch / v, the usage is: find / v "Abc" test.txt, which means to find lines that do not contain the string Abc (Abc is case-sensitive), if it is not case-sensitive, then it should be written as find / I / v "Abc" test.txt.
Sometimes, our request is very simple, just want to count the total number of lines containing a string, at this time, we should use the switch / c, write as find / c "abc" test.txt.
What if you want to display the line number at the beginning of each line? Write find / n "abc" test.txt, which displays all the contents of the test.txt, unlike the original text, with a line number at the beginning of each line of content-note that it just adds a line number when it is displayed, and does not really rewrite the contents of the file.
If you see such a command: find / I / v / n "Abc" test.txt, please be calm first, do not be dazzled by the numerous switches down, carefully compare the above explanation, I believe you will soon understand its function: in the test.txt file, find all the lines that do not contain the string Abc, and mark the line numbers at the beginning of the line, when looking for the string Abc is not case-sensitive.
What would happen if you used the statement find / c / n "abc" test.txt? The answer is: the switch / n will be ignored, and the final result will not show the contents of lines with line numbers, but only the total number of lines that match.
Echo abcdef | find "abc", have you seen this way of writing? What it means is: in the string abcdef, detect the existence of the string abc, that is, find supports pipe symbols and takes the execution result of the statement before the pipe symbol as the search object of the specified string. You can even use the statement: find "abc" test.txt | find "xyz", which means to find lines in test.txt that contain both the string abc and the string xyz, as long as you like. You can continue to concatenate this find statement with pipe symbols, a process we call multifiltering.
As we said earlier, quotation marks are required in the command statement "string to find" in find. What if what we are looking for is the double quotation marks themselves?
The answer is simple: escape the double quotation mark itself in double quotation marks, then put it in the double quotation mark pair and write it in the format of find "test.txt. If you want to find two consecutive double quotes, it should be written as find" test.txt.
If you want to find character blocks between two lines, I advise you to give up this crazy idea as soon as possible, because find only targets strings on the same line, not cross-line character blocks.
It is true that find is much more limited than the findstr command, and many people regard it as a chicken rib simply because it does not support regular expressions, which has been mercilessly abandoned.
However, find is not useless. With its unique skills, it has earned a place in the competition with findstr.
What are these unique stunts? (thanks for the reminder from BatCoder and the supplement from zqz0012005)
1. Count the total number of lines containing the specified string. Find / c "abc" test.txt can count the total number of lines containing the string abc in test.txt, but findstr does not provide this function directly, so it needs to be implemented with for statement.
2. Find can read text in Unicode format, but findstr cannot
3. Find can filter some special characters, but findstr can't. For example, when we use the fsutil fsinfo drives statement to query disk partitions, if we want the drive letter to be displayed on a line rather than on the same line (which is useful when using the for statement to extract the drive letter), find can do well, while findstr can only stare, saying: fsutil fsinfo drives | find / v ""
The above is all the contents of the article "how to use find commands in cmd". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.