Searching Stack Overflow from Linux Terminal Using SoCLI Tool
Last Updated :
12 Mar, 2021
SoCLI is a command-line tool written in python used to search queries on the stack overflow. We can search anything on stack overflow using the SoCLI tool without using the terminal. You can search for any question on Stack overflow on the terminal using SoCLI tool.
Installation of SoCLI:
Let’s see how to install the SoCLI tool on Linux. The prerequisite to install SoCLI is Python 3.5 or higher and pip.
First, we are going to install the prerequisites on the system. To install prerequisite on Debian based systems like Ubuntu or Kali Linux use the following commands:
sudo apt-get install python3 python3-pip
To install prerequisites on arch based system use the following command:
sudo pacman -S python3
sudo pacman -S python3-pip
Now let’s install the SoCLI using the git clone command. We are going to install the SoCLI using the pip command
pip install socli
Usage of SoCLI
Now let’s see how to use SoCLI. To see all options to use SoCLI run the help command to SoCLI.
socli -h
Then in output, we can see that all option that can be used with the socli. The output of the above command is like
To search query on the SoCLI use the following command:
socli <Search Query>
Here in the place of <Search Query> replace the query whatever you want. This command shows the most voted answer on the Stack Overflow Here is example
socli how to install git on linux
Then SoCLI will show the and from Stack Overflow. The output of the above command is
We can use the -q option to specify the search query in socli like.
socli -q how to install git on linux
Getting question by Number:
To get the list of all questions similar to searched query. The SoCLI provides the option -iq. By using this option we can get the list of questions. Then we have to choose the question number. The SoCLI will be to show the answer to that question.
socli -iq <Search Query>
Now let’s see an example of this. We are going to search the query What is the data type in CPP.
socli -iq What are the data type in cpp
Then we will get the list of the question as follows:
Then enter the question number as an input. Here in this case we are selecting 2 questions Then the output is as follows:
Search by Tag
Stack Overflow supports the topic by using tags. socli allows you to query Stack Overflow based on specific tags. Use the -t option to search based on the topic.
socli -t <TAG> -q <QUERY>
In the above command replace the tag with whatever tag you want you can get all tags in Stack Overflow from here. And in place of <QUERY> replace your query here is an example:
socli -t c++ -q what is pointers
Then the output will be like follows:
Options to use with SoCLI
# -r option:
By using this option the SoCLI will show the answer to the nth question from the result of the search query.
socli -r n -q query
Here replace the n with the number of questions you want to see.
Example of -r option:
socli -r 3 -q for loop in C++
Here -q option is used to specify the query. In this example, the answer to the 3rd question will be displayed.
# -n option:
By using this option we can post new question stack overflow. This option will open the Stack Overflow into the browser.
socli -n
There are many commands you can use with SoCLI. To explore those commands use the -h option. If you face any problem while installing the SoCLI then comment below.
Share your thoughts in the comments
Please Login to comment...