TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
> operator is a shell redirection control operator that instructs the Bash shell to redirect the standard output (stdout, file descriptor 1) of a command into a specified file. When evaluated, the shell opens the target file for writing, creating the file if it does not exist, or truncating it to zero length if it already exists.
Syntax
1:
Technical Mechanics
- Execution Order: Redirection is handled entirely by the shell before the command is executed. The shell performs an
open()system call on the target file with the flagsO_WRONLY | O_CREAT | O_TRUNC. Consequently, if you redirect to an existing file, its contents are destroyed before the command even begins processing. - Empty Commands: Because the shell processes the redirection first, executing
> filenamewith no preceding command is a valid, highly efficient way to truncate an existing file to zero bytes or create an empty file. - File Descriptor Isolation: The
>operator strictly redirects stdout. Standard error (stderr, file descriptor2) remains attached to the controlling terminal unless explicitly redirected.
Variations and Modifiers
The> operator serves as the foundation for several other redirection constructs in Bash:
- Specific File Descriptors: Prepending a number redirects that specific file descriptor.
- Combined Output: Bash provides syntax to redirect both stdout and stderr to the same file simultaneously.
- Clobber Override (
>|): Bash includes a shell option callednoclobber(set -o noclobberorset -C). When enabled, the shell will refuse to truncate an existing file using the standard>operator, returning an error instead. The>|operator forces the redirection, bypassing thenoclobberrestriction and truncating the file anyway.
Master Bash with Deep Grasping Methodology!Learn More





