Using the ddgr command to Search DuckDuckGo (with examples)
The ddgr
command is a powerful tool for searching DuckDuckGo from the terminal. In this article, we will explore various use cases of the ddgr
command and provide code examples for each case.
1: Starting in interactive mode
To start ddgr
in interactive mode, simply run the following command:
ddgr
Motivation:
Interactive mode provides a user-friendly way to interact with the DuckDuckGo search engine from the terminal. It allows you to enter your search query and view the search results directly within the command-line interface.
Example output:
# Enter your search query
> software development
# View search results
1. Title: Software development - Wikipedia
URL: https://en.wikipedia.org/wiki/Software_development
Snippet: Software development is the process of conceiving,
specifying, designing, programming, documenting, testing, and ...
2. Title: What is software development? - Definition from
WhatIs.com
URL: https://whatis.techtarget.com/definition/software-development#:~:text=Software%20development%20is%20the%20process%20of%20conceiving%2C%20specifying%2C%20designing%2C%20programming%2C%20documenting%2C%20testing%2C%20and%20bug%20fixing%20involved%20in%20creating%20and%20maintaining%20applications%2C%20frameworks%20or%20other%20software%20components.
Snippet: Software development is the process of conceiving,
specifying, designing, programming, documenting, testing, and ...
# Search again or enter a number to open the result in browser
2: Searching DuckDuckGo for a keyword
To search DuckDuckGo for a specific keyword, run the following command:
ddgr keyword
Motivation:
This use case is useful for quickly searching DuckDuckGo from the terminal without opening a web browser. It allows you to retrieve search results for a specific keyword without leaving your command-line interface.
Example output:
# Search for keyword "linux"
1. Title: Linux - Wikipedia
URL: https://en.wikipedia.org/wiki/Linux
Snippet: Linux is a family of open-source Unix-like
operating systems based on the Linux kernel, an
operating system kernel first released on September 17, 1991,
by Linus Torvalds.
# Search again or enter a number to open the result in browser
3: Limiting the number of search results
To limit the number of search results to N
, use the -n
option followed by the desired number N
:
ddgr -n N keyword
Motivation:
Limiting the number of search results can be helpful when you only want to view a specific number of results, especially for large search queries with numerous results. It allows you to focus on the most relevant results and avoid overwhelming output.
Example output:
# Search for keyword "programming" with 2 search results
1. Title: Programming - Wikipedia
URL: https://en.wikipedia.org/wiki/Programming
Snippet: Programming is the process of designing and
building an executable computer program to accomplish
a specific computing result or to perform a specific task.
2. Title: Computer programming - Wikipedia
URL: https://en.wikipedia.org/wiki/Computer_programming
Snippet: Computer programming is the process of designing
and building an executable computer program to accomplish
a specific computing result or to perform a specific task.
# Search again or enter a number to open the result in browser
4: Displaying the complete URL in search results
To display the complete URL along with the search results, use the -x
option:
ddgr -x keyword
Motivation:
Displaying the complete URL can provide additional context and information about the search results. This can be particularly useful when you want to quickly identify the source of the information or navigate to a specific website directly from the command-line interface.
Example output:
# Search for keyword "python" with complete URLs
1. Title: Welcome to Python.org
URL: https://www.python.org/
Snippet: The official home of the Python Programming Language.
2. Title: Python (programming language) - Wikipedia
URL: https://en.wikipedia.org/wiki/Python_(programming_language)
Snippet: Python is an interpreted high-level general-purpose...
# Search again or enter a number to open the result in browser
5: Searching DuckDuckGo and opening the first result in the browser
To search DuckDuckGo for a keyword and open the first result in the browser, use the following command:
ddgr !w keyword
Motivation:
This use case allows you to quickly jump to the first search result in your browser without having to manually copy and paste the URL. It can be especially handy when you want to view a specific webpage related to your search query.
Example output:
# Search for keyword "docker" and open the first result in the browser
1. Title: Docker - Build, Ship, and Run Any App, Anywhere
URL: https://www.docker.com/
Snippet: Docker container platform is the only container platform
to build, secure and manage the entire container lifecycle
from legacy to hybrid to multicloud.
# Opening the first result in the browser...
6: Performing a website-specific search
To perform a website-specific search on DuckDuckGo, use the -w
option followed by the website URL and the keyword:
ddgr -w site keyword
Motivation:
Performing a website-specific search allows you to narrow down your search results to a specific domain or website. This can be useful when you want to find information from a particular source or exclude results from other domains.
Example output:
# Perform a website-specific search on Wikipedia with the keyword "linux"
1. Title: Linux - Wikipedia
URL: https://en.wikipedia.org/wiki/Linux
Snippet: Linux is a family of open-source Unix-like
operating systems based on the Linux kernel, an
operating system kernel first released on September 17, 1991,
by Linus Torvalds.
# Search again or enter a number to open the result in browser
7: Searching for a specific file type
To search DuckDuckGo for a specific file type, use the filetype
modifier:
ddgr keyword filetype:filetype
Motivation:
Searching for a specific file type can help you find specific documents or resources related to your search query. This is particularly useful when you are looking for specific file formats such as PDFs, images, or source code files.
Example output:
# Search for the keyword "example" with the file type "pdf"
1. Title: Example PDF File
URL: https://example.com/myfile.pdf
Snippet: This is an example PDF file for demonstration purposes.
# Search again or enter a number to open the result in browser
8: Displaying help in interactive mode
To display the help message within the interactive mode, simply enter ?
.
Motivation:
The help message provides detailed information about the available options and commands in the interactive mode. It can serve as a quick reference when you are unsure about a specific command or need assistance with using ddgr
.
Example output:
# Enter '?' in the interactive mode to display the help message
# Display the help message
?
Conclusion
The ddgr
command offers a convenient way to search DuckDuckGo directly from the terminal. By utilizing various options and modifiers, you can customize your search queries, limit the number of results, and even perform site-specific searches. The code examples provided in this article demonstrate the versatility and power of ddgr
, allowing you to harness the full potential of DuckDuckGo search in your command-line workflow.