In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces which command line search tools are commonly used in Linux. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
Grep
The advantage of using grep is that it can be used on almost any Unix-like system. I'm sure you've all heard of the power of this order. Let me show you some of the ways I use the grep command most often.
If you just want to find a keyword in the py file and output the line number, you can do this:
$grep-rins-include\ * .py import.
Suppose we entered a more complex command on the command line a few days ago, but now we only recall part of the command. Then we can use the grep command through the pipeline (|) to search for history commands:
$history | grep "python"
After this command is executed, we can find all the commands we have run that contain the python keyword, and then we can pass! To re-execute this order.
$history | grep "python" 284 python test.py. # omit other results $! 284$ python test.py
Ack
Ack is relatively less familiar. It is "a tool similar to grep and optimized for programmers." It searches recursively by default, but ignores versioning tool catalogs, such as .git directories. And it comes with a lot of very practical tools, which can greatly improve our search efficiency.
Let's also give the above example. Let's use the ack command to implement the method of searching only the import keyword in the py file:
# ack command implementation $ack import-- py # grep command implementation $grep-rins-- include\ * .py import.
The above is only searched in py files, so what if we want to search for all other types of files except py file types?
For each file type, there is a corresponding no identity to exclude the search for that file type. For example, use the-- py option if you want to search for py files, and use the-- nopy option if you want to exclude py files.
$ack import-nopy
Of course, there are many file types, and we can also expand the file types by modifying the ~ / .ackrc file. If we want to search for .conf files now, ack does not support such files by default:
$ack hello-- conf Unknown option: conf ack: Invalid option on command line
To register the .conf file type, we can add the following to the ~ / .ackrc file, and then we can search for the conf file normally.
-- type-set=conf=.conf
After the configuration file has been modified, we can use the-- help-types option to confirm that the custom type has been successfully added.
The ack command gets the configuration information from the .ackrc file, but if you want to run the ack command without the .ackrc file, you can use the-noenv option.
The Silver Searcher
The searcher is another grep alternative similar to ack, and its faster performance is highly appreciated. A very practical feature is that it ignores the files specified in the .gitignore file in the project project. So if you want to rule out searching for some files, you can write those files in the .gitignore file.
If you may not be familiar with the silver searcher, its other name can be a bit like thunder: the ag command.
You can install the ag command on a Ubuntu system by using the following command:
$apt-get install silversearcher-ag
Use the ag command to search for the contents of the py file that contain the keyword import:
$ag import-py
The ag command is so powerful that this article will only introduce its most basic usage, and supplement its other very powerful uses if you have time some other time.
Sift
Sift is an alternative to grep written in Golang, which means it can be used on Linux,Windows,OS X and other systems. It's ridiculously fast, and there are some cool use cases to extract data instead of grep + awk.
We then use the sift command to search all py files that contain the import keyword:
# search only py files: sift-- ext py import # exclude py files sift-- exclude-ext py import
RipGrep
RipGrep is similar to Silver Searcher and can be run on Mac, Linux, and Windows. Its readme file claims that RipGrep is usually faster than any other search tool. It favors Rust's regular expression engine and, like Silver Searcher, uses .gitignore files to exclude files or directories.
RipGrep is usually referred to as rg for short, and we use the rg command to search all py files that contain the import keyword:
Rg-type=py import above are all the contents of the article "what are the command line search tools commonly used in Linux?" Thank you for reading! Hope to share the content to help you, more related 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.