Standard Streams and File Descriptors

Updated

October 31, 2026

Standard Streams and File Descriptors

Linux processes inherit three default file descriptors: * 0: stdin (Standard Input) * 1: stdout (Standard Output) * 2: stderr (Standard Error)

Custom descriptors (3 to 9) can be allocated for custom logging or teeing:

# Allocate FD 3 to write to a log file
exec 3> /var/log/custom-audit.log

# Write directly to FD 3
echo "Audit event at $(date)" >&3

# Close FD 3
exec 3>&-