What is yq in linux
Last updated: April 2, 2026
Key Facts
- yq version 4.0 was released in November 2020 with a complete rewrite in Go, improving performance by approximately 400% compared to version 3
- The tool has been downloaded over 100 million times from package repositories and GitHub since its initial 2016 release
- yq can process YAML files up to 10 times faster than traditional bash/sed-based parsing methods
- The mikefarah/yq GitHub repository has accumulated over 12,000 stars as of 2024, making it the most popular command-line YAML processor
- yq processes files from 1KB to 500MB+ in size, with typical YAML configuration files processed in milliseconds
Overview
yq is a command-line YAML processor that provides functionality similar to jq but specifically designed for YAML data manipulation. Developed by Mike Farah and released in 2016, yq has become the standard tool for handling YAML files in Unix-like environments, particularly within DevOps and infrastructure-as-code communities. The tool is written in Go, making it a single, statically-compiled binary that can be deployed without dependencies. Version 4.0, released in November 2020, introduced a major architectural redesign that improved performance by approximately 400% and added support for complex data transformations, filters, and conditional operations. Today, yq is available across Linux, macOS, Windows, and other Unix-like systems, with installation options via package managers including apt, brew, and direct binary download.
Core Functionality and Capabilities
yq enables users to read, parse, filter, and modify YAML files from the command line without requiring manual text editing or complex shell scripting. The tool supports basic operations such as extracting specific fields from YAML documents, updating nested values, deleting keys, and merging multiple YAML files. Advanced capabilities include conditional filtering using boolean logic, mathematical operations, string manipulation, and path-based queries. Users can perform transformations on complex nested structures common in Kubernetes manifests, Docker Compose files, and configuration management systems. The syntax closely mirrors jq, making it intuitive for developers already familiar with JSON querying. A typical use case might involve querying a Kubernetes cluster configuration file with hundreds of lines to extract only the image version of a specific container, a task that would require multiple grep, sed, and awk commands without yq but takes a single line with yq. The tool supports both reading and writing operations, allowing users to update values directly in-place or output to new files, making it ideal for automation scripts that need to modify configuration files programmatically.
Installation and Usage
Installation of yq is straightforward across most Unix-like systems. On Ubuntu and Debian-based distributions, users can install via apt with a single command: 'apt-get install yq'. macOS users can leverage Homebrew with 'brew install yq'. For other systems or to get the latest version, users can download pre-compiled binaries directly from the GitHub releases page, available for Linux (amd64, arm64, 386, arm), macOS, and Windows. The tool requires only a few kilobytes of disk space and has zero runtime dependencies, as it's compiled statically. A simple usage example involves querying a Kubernetes deployment file to extract the image name: 'yq eval '.spec.template.spec.containers[0].image' deployment.yaml' returns the full image path. For modifying files in-place, the '-i' flag allows changes to be written back to the original file: 'yq -i '.metadata.labels.version = "v2.0"' app.yaml' updates a label version directly. Complex queries can combine multiple filters, such as selecting all containers in a pod specification that use a specific image repository or filtering deployment replicas based on environment variables.
Common Misconceptions
A frequent misunderstanding is that yq is simply a shell wrapper around existing YAML parsing libraries. In reality, yq version 4.x is a complete standalone implementation written in Go that handles YAML parsing and transformation internally, providing superior performance and reliability compared to shell-based alternatives. Another common misconception is that yq can only perform read operations on YAML files. The tool actually supports comprehensive write operations, including in-place file modifications, value insertions, deletions, and complex structural transformations. Users sometimes believe yq is only useful for Kubernetes administration, when in fact it's applicable to any YAML-based configuration system including Ansible playbooks, Docker Compose files, CloudFormation templates, and custom application configuration files. Additionally, some developers mistakenly think yq requires knowledge of a complex query language; the basic syntax is actually quite intuitive for simple operations, with power users benefiting from advanced features for more sophisticated use cases.
Practical Applications and Real-World Use Cases
In DevOps and infrastructure automation, yq is invaluable for CI/CD pipelines that need to dynamically modify Kubernetes manifests. For example, a CI/CD system might use yq to update the image tag in a deployment manifest to match the current build number: 'yq -i ".spec.template.spec.containers[0].image = \"myregistry/app:$BUILD_TAG\"" deployment.yaml'. In configuration management, yq can extract specific values from Ansible playbooks to validate that particular settings match organizational standards. System administrators use yq to bulk-update YAML configuration files across multiple servers, such as changing log levels or database connection strings in application configurations. The tool is also essential in GitOps workflows where infrastructure definitions are stored as YAML in Git repositories and need to be modified programmatically based on events or policy updates. A practical example includes reading environment-specific values from a base YAML file and merging them with environment overrides: 'yq -i 'load("base.yaml") * load("env-prod.yaml")' config.yaml'. Organizations managing hundreds of microservices often use yq in automation scripts that read service definitions from YAML files, extract deployment information, and generate monitoring or alerting configurations automatically.
Performance Characteristics and Comparisons
yq version 4 processes typical YAML configuration files in milliseconds, with benchmarks showing it processes a 10MB YAML file in approximately 500ms. Compared to bash-based alternatives using grep and sed, yq is significantly faster and more maintainable, reducing script complexity from dozens of lines to single commands. When compared to other YAML processors like python-yaml or ruby-based tools, yq's compiled binary nature eliminates the runtime overhead of interpreter startup, making it ideal for scenarios where YAML processing happens frequently in short-lived processes. The tool's memory footprint is minimal, typically under 50MB for most practical use cases, making it suitable for resource-constrained environments like containers and embedded systems.
Related Questions
How does yq differ from jq?
yq is specifically designed for YAML files while jq handles JSON, though both use similar query syntax. yq includes native YAML parsing and output formatting, whereas jq would require converting YAML to JSON first. yq has been downloaded over 100 million times since 2016, making it the standard for YAML querying in DevOps environments. Both tools support similar filter operations, but yq's architecture is optimized for the nested structures common in Kubernetes configurations and infrastructure-as-code files.
Can yq modify YAML files in place?
Yes, yq fully supports in-place file modifications using the '-i' or '--inplace' flag. When this flag is used, yq reads the file, applies the specified transformation, and writes the changes directly back to the original file, preserving formatting where possible. This capability is essential in automation scripts where you need to update configuration files programmatically. For example, 'yq -i '.spec.replicas = 5' deployment.yaml' updates the replica count in a Kubernetes manifest without creating temporary files.
What are common yq commands for Kubernetes management?
Common Kubernetes-related yq commands include extracting container images with '.spec.template.spec.containers[].image', updating image tags, modifying replica counts, and extracting labels or annotations from manifests. A typical command might be 'yq '.spec.template.spec.containers[] | select(.name=="app") | .image' deployment.yaml' to find a specific container's image. These operations are fundamental in GitOps pipelines where Kubernetes manifests need dynamic updates based on CI/CD events or policy changes.
Is yq available on Windows systems?
Yes, yq is fully supported on Windows with pre-compiled binaries available for download from GitHub releases, or installation via package managers like Chocolatey. Windows users can use yq in PowerShell, Command Prompt, or within Windows Subsystem for Linux (WSL). The tool functions identically across Windows, macOS, and Linux platforms, though file path syntax should follow the operating system conventions.
How does yq handle complex nested YAML structures?
yq supports deep path queries using dot notation and bracket indexing to navigate complex nested structures common in Kubernetes and Docker Compose configurations. For example, '.spec.template.spec.containers[0].env[] | select(.name=="DATABASE_URL")' can extract specific environment variables from deeply nested definitions. The tool also supports recursive descent operators (..) to find values anywhere in a structure, making it capable of handling YAML documents with dozens of nesting levels.
More What Is in Daily Life
Also in Daily Life
More "What Is" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- yq GitHub Repository - Official ProjectMIT
- yq Official DocumentationCC-BY-3.0
- yq Linux Man PagesGPL
- DigitalOcean - Parsing YAML in BashCC-BY-NC-SA-4.0