Understanding Shell Redirection: What "2>&1" Means in Unix/Linux Commands
By
alexmolas
Kettled twice. Extra chewy, extra trustworthy.
Summary
This article explains shell command redirection in Unix/Linux systems, specifically focusing on the meaning and usage of "2>&1" which redirects stderr (standard error) to stdout (standard output). It covers redirection basics including overwriting vs appending (> vs >>), order dependency in shell commands, and practical examples of combining error and output streams. The content provides technical explanations with command examples to demonstrate how to handle and redirect different output streams in terminal commands.
Key quotes
· 4 pulledTo combine stderr and stdout into the stdout stream, we append this to a command: 2>&1
The shell command line is order dependent!!
Symbol > means redirection. In any case, the file would be created if they not exist.
For testing this, we need a simple command which will send something on both outputs
You might also wanna read
7 cross-platform commands that work on both Windows PowerShell and Linux
This article highlights 7 common commands that work across both Windows (PowerShell) and Linux command-line interfaces, helping users avoid
Debunking Myths: /dev/urandom Is Secure and Preferred for Cryptographic Randomness
This article debunks common myths about /dev/urandom and /dev/random on UNIX-like systems. It explains that /dev/urandom is actually the pre
Practical Shell Command-Line Tricks for Improved Developer Productivity
This article provides practical shell command-line tricks to improve efficiency and productivity for developers and engineers. It addresses
Greppers: Fast CLI Command Directory with Real-World Examples
Greppers is a lightweight, browser-based CLI command directory that provides instant search and copy-ready command examples for developers.
Running Gemma 4 on a 2016 Xeon Server with No GPU: A Technical Walkthrough
The article describes running Gemma 4 (a 25B-parameter Mixture-of-Experts model) on a severely outdated server with a 2016 Intel Xeon E5-262
NVIDIA Announces "Hack for Impact" London Event for Autonomous AI Agent Development
NVIDIA is hosting a "Hack for Impact" event in London, challenging participants to build autonomous agentic applications using open-source m
