Table of contents
1.
Introduction
2.
Knife Subcommands
2.1.
Knife Command Syntax
2.2.
Built-in Subcommands
3.
Verb Subcommands
3.1.
Wildcard Search
4.
Knife Plug-ins 
4.1.
Plugin Installation
4.2.
Chef Maintained Knife Plugins
5.
Frequently Asked Questions
5.1.
What is the use of the knife bootstrap command?
5.2.
Which command is used to run Ruby scripts?
5.3.
Which command is used to install a Knife plugin?
6.
Conclusion
Last Updated: Aug 13, 2025

About Knife

Author Nagendra
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Knife is a command-line utility that acts as an interface between a local chef-repo and the Chef Infra Server. Knife aids users in managing Nodes, Recipes, cookbooks, Environments, roles, and data bags, Various cloud environments' resources, the process of installing the Chef Infra Client on nodes, and searching through the Chef Infra Server's index of data.

This blog explains the details of Knife along with the details of Knife Subcommands, Verb Subcommands, and Knife Plug-ins.

Without further ado, let's get started.

Chef Image

Knife Subcommands

Cookbooks, nodes, data bags, roles, environments, and users are just a few of the objects in an organisation that may be targeted with precise actions using Knife's built-in subcommands.

Knife Command Syntax

The syntax for all knife subcommands is as follows:

Command:

knife subcommand [ARGUMENT] (options)

 

Each subcommand has a unique set of options and arguments.

Built-in Subcommands

The following are the Built-in Subcommands of 

  • knife_bootstrap
    This subcommand is used to run a bootstrap operation that installs Chef Infra Client on the target system. The IP address or FQDN of the destination system must be specified during the bootstrap operation.
     
  • knife_client
    This subcommand is used to handle an API client list and the RSA public key pairs that go with it. Any entity that uses the Chef Infra Server API, such as the Chef Infra Client and Knife, can now send authentication requests to the Chef Infra Server.
     
  • knife configure
    This subcommand is used to create the client.rb and credential files and then distribute them to workstations and nodes.
     
  • knife cookbook
    To communicate with cookbooks that are kept on the local chef-repo or the Chef Infra Server, use the knife cookbook subcommand.
     
  • Data knife bag
    This subcommand is used to utilize the knife data bag subcommand to manage arbitrary JSON data stores that are accessible worldwide.
     
  • knife delete
    This subcommand is used for the purpose of removing an item from a Chef Infra Server. With just a single verb, this subcommand performs operations akin to those of the knife cookbook delete, knife data bag delete, knife node deletes, knife environment delete, and knife role delete commands (and a single action).
     
  • knife deps
    This subcommand is used to determine the dependencies for a node, role, or cookbook using the knife deps subcommand.

 

  • knife diff
    This subcommand is used to compare the differences between the files and directories on the Chef Infra Server and in the chef-repo. For instance, to check that particular files are the same across several production environments before utilising the knife download and knife upload subcommands to upload or download files from the Chef Infra Server. This subcommand can be used to compare what is in the chef-repo with what has been synced to a git repository, much like the git diff command.

 

  • knife download
    Using the knife download subcommand, you can download roles, cookbooks, environments, nodes, and data bags to the current working directory from the Chef Infra Server. It can be used to extract out-of-process modifications users may have made to the files on the Chef Infra Server, such that if a user made a change that obviated version source control, investigate the state of one or more files, or back up data on the Chef Infra Server. Knife upload, which performs the opposite of knife download, and knife diff, which may be used to examine exactly what changes will be downloaded, are frequently used in conjunction with this subcommand.
     
  • knife edit
    This subcommand is used to modify objects on the Chef Infra Server. Similar to the knife role edit, knife environment edit, knife node edit, knife cookbook edit, and knife data bag edit, but with just one verb (and a single action).

 

  • knife environment
    On the Chef Infra Server, use the knife environment subcommand to manage environments for a single organisation.
     
  • knife exec
    You can use the knife exec subcommand to run Ruby scripts inside of a Chef Infra Client that is properly set up. Use this subcommand in order to run scripts that will only seldom (or once) visit the Chef Infra Server or whenever the action does not require full use of the knife subcommand library.
     
  • knife list
    This subcommand is used to view a list of items on the Chef Infra Server. With only one verb, this subcommand functions similarly to the knife data bag list, knife environment list, knife node list, and knife role list (and a single action).

 

  • knife node
    This subcommand is used for control over the nodes that are present on a Chef Infra Server.
     
  • knife raw
    This subcommand is used to send a REST call to an endpoint in the Chef Infra Server API.
     
  • knife recipe list
    This subcommand is used to view every recipe on a Chef Infra Server. Use a regular expression to restrict the results to recipes that adhere to a given pattern. There must be quotation marks around the regular expression and no forward slashes (/).
     
  • knife role
    This subcommand is used to handle the roles connected to one or more nodes on a Chef Infra Server.
     
  • knife search
    Run a search query for data that is indexed on a Chef Infra Server using the knife search subcommand.
     
  • knife serve
    This subcommand is used to perform a persistent chef-zero against the local chef-repo. This is equivalent to launching the Chef Infra Client executable in local mode. The Chef Infra Server will automatically locate the chef-repo path and bind to the first open port between 8889 and 9999. The local Chef Infra Server's URL will be printed by Knife serve so that it may be added to the config.rb file.
     
  • knife show
    This subcommand inspects the specifics of one (or more) object on the Chef Infra Server. With just one verb, this subcommand performs operations akin to those of the knife cookbook show, knife data bag show, knife environment show, knife node show, and knife role show (and a single action).
     
  • knife ssh
    Invoke SSH operations (in parallel) on a selection of nodes within an organisation using the knife ssh subcommand, based on the outcomes of a search query sent to the Chef Infra Server.
     
  • knife ssl check
    This subcommand is used to check the SSL configuration for the Chef Infra Server or a destination indicated by a URL or URI. The OpenSSL protocol will not use invalid certificates.
     
  • knife ssl fetch
    This subcommand is used to copy SSL certificates from an HTTPS server to the trusted certs dir directory, which Knife and Chef Infra Client use to hold trusted SSL certificates. Running knife ssl fetch is the sole action necessary to confirm a remote server that is reached by either knife or Chef Infra Client when these certificates match the hostname of the remote server.
     
  • knife status
    You may get a quick rundown of the nodes on a Chef Infra Server, along with the time of the recent successful Chef Infra Client run, by using the knife status subcommand.
     
  • knife tag
    Using the knife tag subcommand, you can tag nodes on a Chef Infra Server.
     
  • knife supermarket
    This subcommand is used to communicate with the cookbooks that are offered in the Chef Supermarket. Any community activity that writes data to this site requires a user account. Downloading, installing, and listing arguments don't require a user account.
     
  • knife upload
    To upload data from the chef-current repo's working directory to the Chef Infra Server, use the knife upload subcommand. With the use of this subcommand, the following data types may be uploaded:
    • Cookbooks
    • Data bags
    • Roles stored as JSON data
    • Environments stored as JSON data
      Knife diff, which can be used to view exactly what changes will be posted, and knife download, which performs the opposite of knife upload, are frequently used in conjunction with this subcommand.
       
  • knife user
    This subcommand is used to manage the list of users and the RSA public key pairs that are associated with them.
     
  • knife xargs
    This subcommand is used to download patterns from standard input as JSON, run a program against the JSON, and then upload any modifications.

 

Let's look into the details of Verb Subcommands.

 

Verb Subcommands

Knife has a number of subcommands designed on popular verbs, including delete, deps, diff, download, edit, list, show, upload, and xargs. Through the use of these subcommands, Knife is able to give instructions that interact with any item kept in the chef-repo or kept on the Chef Infra Server. This category of subcommands is underpinned by several significant principles, such as:

  • A command that is compatible with every item in the chef-repo. The subcommands indicate the action that should be taken (the "verb") as well as the object's location (clients, cookbooks/data_bags/environments/nodesroles/, and users). Using the following example: download cookbooks/.
     
  • A command that operates on specific Chef Infra Server objects, such as acls, groups, and containers.
     
  • It uses the Chef Infra Server as if it were a file system, enabling the chef-repo on the server to function similarly to the workstation's chef-repo. The local chef-repo and the Chef Infra Server will both contain the same items. Simply download files from the Chef Infra Server or upload files from the chef-repo to make modifications to the files there.
     
  • It matters from what context a command is executed. For instance, Knife will be aware of what is being dealt with when working in the roles/ directory. Knife will return the basic role from the Chef Infra Server when you type knife show base.json. Enter knife show roles/base.json from the chef-repo root to achieve the same outcome.
     
  • The Chef Infra Server supports simultaneous queries, which can be configured for each command.

Wildcard Search

When replacing zero or more characters in a substring match, a wildcard matching pattern can be employed. Wildcard patterns come in two types:

  • There is precisely one character that can be substituted with a question mark ("?"). (as long as that character is not the first character).
     
  • Any number of characters can be substituted with an asterisk ("*"). (including zero)
     

To ensure that the wildcard itself reaches the Chef Infra Server, wildcard patterns must be escaped (by adding a backslash). The wildcard expands into the actual filenames if they are not escaped, making Knife unaware that the wildcard was supposed to be used. For instance, escaping vs. not escaping the wildcard pattern will produce different results if the Chef Infra Server has data bags named aardvarks, anagrams, and arp_tables while the local file system only has aardvarks and anagrams:

Command:

knife list data_bags/a\*

 

Output:

aardvarks/ anagrams/ arp_tables/


Command:

knife list data_bags/a*

 

Output:

aardvarks/ anagrams/


Command:

knife list data_bags/aardvarks data_bags/anagrams

 

Output:

aardvarks/ anagrams/

 

Let's look into the details of Knife Plugins.

Knife Plug-ins 

Plugins, which behave similarly to built-in subcommands, can be used to increase the capability of knives (including common options). To communicate with popular cloud providers, streamline typical Chef procedures, and support Chef workflows, knife plugins have been developed.

Plugin Installation

The chef command is used to install knife plugins into the Chef Workstation installation. Knife plugins are shipped as RubyGems.

Command:

chef gem install PLUGIN_NAME

 

You must perform the following commands after installation to rehash the list of knife commands:

Command:

knife rehash

Chef Maintained Knife Plugins

The following plugins, which come with Chef Workstation, are maintained by Chef:

  • knife-acl
     
  • knife-azure
     
  • knife-rackspace
     
  • knife-google
     
  • knife-lpar
     
  • knife-opc
     
  • knife-ec2
     
  • knife-openstack
     
  • knife-reporting
     
  • knife-vcenter
     
  • knife-windows
     

Frequently Asked Questions

What is the use of the knife bootstrap command?

The chef-client may typically be installed on a node using the knife bootstrap command. This method's default assumption is that node can access the Chef website and download the chef-client package there.

Which command is used to run Ruby scripts?

To run Ruby scripts within the context of a full set-up Chef Infra Client, use the knife exec subcommand.

Which command is used to install a Knife plugin?

Knife plugin can be installed using chef gem install command.

Conclusion

In this article, we have extensively discussed the details of Knife along with the details of Knife Subcommands, Verb Subcommands, and Knife Plug-ins.

We hope that this blog has helped you enhance your knowledge regarding Knife, and if you would like to learn more, you can refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc. To practice and improve yourself in the interview, you can also check out Top 100 SQL problemsInterview experienceCoding interview questions, and the Ultimate guide path for interviews. Do upvote our blog to help other ninjas grow. Happy Coding!!

Thank You image
Live masterclass